home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / text / edit / vim60rt.lha / Vim / vim60 / doc / eval.txt < prev    next >
Encoding:
Text File  |  2001-09-26  |  117.9 KB  |  3,111 lines

  1. *eval.txt*      For Vim version 6.0.  Last change: 2001 Sep 16
  2.  
  3.  
  4.           VIM REFERENCE MANUAL    by Bram Moolenaar
  5.  
  6.  
  7. Expression evaluation            *expression* *expr* *E15* *eval*
  8.  
  9. Using expressions is introduced in chapter 41 of the user manual |usr_41.txt|.
  10.  
  11. Note: Expression evaluation can be disabled at compile time.  If this has been
  12. done, the features in this document are not available.  See |+eval| and the
  13. last chapter below.
  14.  
  15. 1. Variables        |variables|
  16. 2. Expression syntax    |expression-syntax|
  17. 3. Internal variable    |internal-variables|
  18. 4. Builtin Functions    |functions|
  19. 5. Defining functions    |user-functions|
  20. 6. Curly braces names    |curly-braces-names|
  21. 7. Commands        |expression-commands|
  22. 8. Examples        |eval-examples|
  23. 9. No +eval feature    |no-eval-feature|
  24. 10. The sandbox        |eval-sandbox|
  25.  
  26. {Vi does not have any of these commands}
  27.  
  28. ==============================================================================
  29. 1. Variables                        *variables*
  30.  
  31. There are two types of variables:
  32.  
  33. Number        a 32 bit signed number.
  34. String        a NUL terminated string of 8-bit unsigned characters.
  35.  
  36. These are converted automatically, depending on how they are used.
  37.  
  38. Conversion from a Number to a String is by making the ASCII representation of
  39. the Number.  Examples: >
  40. Number 123    -->    String "123"
  41. Number 0    -->    String "0"
  42. Number -1    -->    String "-1"
  43.  
  44. Conversion from a String to a Number is done by converting the first digits
  45. to a number.  Hexadecimal "0xf9" and Octal "017" numbers are recognized.  If
  46. the String doesn't start with digits, the result is zero.  Examples: >
  47. String "456"    -->    Number 456
  48. String "6bar"    -->    Number 6
  49. String "foo"    -->    Number 0
  50. String "0xf1"    -->    Number 241
  51. String "0100"    -->    Number 64
  52.  
  53. To force conversion from String to Number, add zero to it: >
  54. :echo "0100" + 0
  55.  
  56. For boolean operators Numbers are used.  Zero is FALSE, non-zero is TRUE.
  57.  
  58. Note that in the command >
  59. :if "foo"
  60. "foo" is converted to 0, which means FALSE.  To test for a non-empty string,
  61. use strlen(): >
  62. :if strlen("foo")
  63.  
  64. If you need to know the type of a variable or expression, use the |type()|
  65. function.
  66.  
  67. When the '!' flag is included in the 'viminfo' option, global variables that
  68. start with an uppercase letter, and don't contain a lowercase letter, are
  69. stored in the viminfo file |viminfo-file|.
  70.  
  71. When the 'sessionoptions' option contains "global", global variables that
  72. start with an uppercase letter and contain at least one lowercase letter are
  73. stored in the session file |session-file|.
  74.  
  75. variable name        can be stored where ~
  76. my_var_6        not
  77. My_Var_6        session file
  78. MY_VAR_6        viminfo file
  79.  
  80.  
  81. It's possible to form a variable name with curly braces, see
  82. |curly-braces-names|.
  83.  
  84. ==============================================================================
  85. 2. Expression syntax                    *expression-syntax*
  86.  
  87. Expression syntax summary, from least to most significant:
  88.  
  89. |expr1| expr2 ? expr1 : expr1    if-then-else
  90.  
  91. |expr2|    expr3 || expr3 ..    logical OR
  92.  
  93. |expr3|    expr4 && expr4 ..    logical AND
  94.  
  95. |expr4|    expr5 == expr5        equal
  96. expr5 != expr5        not equal
  97. expr5 >     expr5        greater than
  98. expr5 >= expr5        greater than or equal
  99. expr5 <     expr5        smaller than
  100. expr5 <= expr5        smaller than or equal
  101. expr5 =~ expr5        regexp matches
  102. expr5 !~ expr5        regexp doesn't match
  103. expr5 ==? expr5        equal, ignoring case
  104. expr5 ==# expr5        equal, match case
  105. etc.  As above, append ? for ignoring case, # for matching case
  106.  
  107. |expr5|    expr6 +     expr6 ..    number addition
  108. expr6 -     expr6 ..    number subtraction
  109. expr6 .     expr6 ..    string concatenation
  110.  
  111. |expr6|    expr7 *     expr7 ..    number multiplication
  112. expr7 /     expr7 ..    number division
  113. expr7 %     expr7 ..    number modulo
  114.  
  115. |expr7|    ! expr7            logical NOT
  116. - expr7            unary minus
  117. + expr7            unary plus
  118. expr8
  119.  
  120. |expr8|    expr9[expr1]        index in String
  121.  
  122. |expr9|    number            number constant
  123. "string"        string constant
  124. 'string'        literal string constant
  125. &option            option value
  126. (expr1)            nested expression
  127. variable        internal variable
  128. va{ria}ble        internal variable with curly braces
  129. $VAR            environment variable
  130. @r            contents of register 'r'
  131. function(expr1, ...)    function call
  132. func{ti}on(expr1, ...)    function call with curly braces
  133.  
  134.  
  135. ".." indicates that the operations in this level can be concatenated.
  136. Example: >
  137. &nu || &list && &shell == "csh"
  138.  
  139. All expressions within one level are parsed from left to right.
  140.  
  141.  
  142. expr1                            *expr1* *E109*
  143. -----
  144.  
  145. expr2 ? expr1 : expr1
  146.  
  147. The expression before the '?' is evaluated to a number.  If it evaluates to
  148. non-zero, the result is the value of the expression between the '?' and ':',
  149. otherwise the result is the value of the expression after the ':'.
  150. Example: >
  151. :echo lnum == 1 ? "top" : lnum
  152.  
  153. Since the first expression is an "expr2", it cannot contain another ?:.  The
  154. other two expressions can, thus allow for recursive use of ?:.
  155. Example: >
  156. :echo lnum == 1 ? "top" : lnum == 1000 ? "last" : lnum
  157.  
  158. To keep this readable, using |line-continuation| is suggested: >
  159. :echo lnum == 1
  160. :\    ? "top"
  161. :\    : lnum == 1000
  162. :\        ? "last"
  163. :\        : lnum
  164.  
  165.  
  166. expr2 and expr3                        *expr2* *expr3*
  167. ---------------
  168.  
  169.                     *expr-barbar* *expr-&&*
  170. The "||" and "&&" operators take one argument on each side.  The arguments
  171. are (converted to) Numbers.  The result is:
  172.  
  173.  input                 output ~
  174. n1        n2        n1 || n2    n1 && n2 ~
  175. zero        zero        zero        zero
  176. zero        non-zero    non-zero    zero
  177. non-zero    zero        non-zero    zero
  178. non-zero    non-zero    non-zero    non-zero
  179.  
  180. The operators can be concatenated, for example: >
  181.  
  182. &nu || &list && &shell == "csh"
  183.  
  184. Note that "&&" takes precedence over "||", so this has the meaning of: >
  185.  
  186. &nu || (&list && &shell == "csh")
  187.  
  188. Once the result is known, the expression "short-circuits", that is, further
  189. arguments are not evaluated.  This is like what happens in C.  For example: >
  190.  
  191. let a = 1
  192. echo a || b
  193.  
  194. This is valid even if there is no variable called "b" because "a" is non-zero,
  195. so the result must be non-zero.  Similarly below: >
  196.  
  197. echo exists("b") && b == "yes"
  198.  
  199. This is valid whether "b" has been defined or not.  The second clause will
  200. only be evaluated if "b" has been defined.
  201.  
  202.  
  203. expr4                            *expr4*
  204. -----
  205.  
  206. expr5 {cmp} expr5
  207.  
  208. Compare two expr5 expressions, resulting in a 0 if it evaluates to false, or 1
  209. if it evaluates to true.
  210.  
  211.             *expr-==*  *expr-!=*  *expr->*   *expr->=*
  212.             *expr-<*   *expr-<=*  *expr-=~*  *expr-!~*
  213.             *expr-==#* *expr-!=#* *expr->#*  *expr->=#*
  214.             *expr-<#*  *expr-<=#* *expr-=~#* *expr-!~#*
  215.             *expr-==?* *expr-!=?* *expr->?*  *expr->=?*
  216.             *expr-<?*  *expr-<=?* *expr-=~?* *expr-!~?*
  217.         use 'ignorecase'    match case       ignore case ~
  218. equal            ==        ==#        ==?
  219. not equal        !=        !=#        !=?
  220. greater than        >        >#        >?
  221. greater than or equal    >=        >=#        >=?
  222. smaller than        <        <#        <?
  223. smaller than or equal    <=        <=#        <=?
  224. regexp matches        =~        =~#        =~?
  225. regexp doesn't match    !~        !~#        !~?
  226.  
  227. Examples:
  228. "abc" ==# "Abc"      evaluates to 0
  229. "abc" ==? "Abc"      evaluates to 1
  230. "abc" == "Abc"      evaluates to 1 if 'ignorecase' is set, 0 otherwise
  231.  
  232. When comparing a String with a Number, the String is converted to a Number,
  233. and the comparison is done on Numbers.
  234.  
  235. When comparing two Strings, this is done with strcmp() or stricmp().  This
  236. results in the mathematical difference (comparing byte values), not
  237. necessarily the alphabetical difference in the local language.
  238.  
  239. When using the operators with a trailing '#", or the short version and
  240. 'ignorecase' is off, the comparing is done with strcmp().
  241.  
  242. When using the operators with a trailing '?', or the short version and
  243. 'ignorecase' is set, the comparing is done with stricmp().
  244.  
  245. The "=~" and "!~" operators match the lefthand argument with the righthand
  246. argument, which is used as a pattern.  See |pattern| for what a pattern is.
  247. This matching is always done like 'magic' was set and 'cpoptions' is empty, no
  248. matter what the actual value of 'magic' or 'cpoptions' is.  This makes scripts
  249. portable.  To avoid backslashes in the regexp pattern to be doubled, use a
  250. single-quote string, see |literal-string|.
  251. Since a string is considered to be a single line, a multi-line pattern
  252. (containing \n, backslash-n) will not match.  However, a literal NL character
  253. can be matched like an ordinary character.  Examples:
  254. "foo\nbar" =~ "\n"    evaluates to 1
  255. "foo\nbar" =~ "\\n"    evaluates to 0
  256.  
  257.  
  258. expr5 and expr6                        *expr5* *expr6*
  259. ---------------
  260. expr6 +     expr6 ..    number addition        *expr-+*
  261. expr6 -     expr6 ..    number subtraction    *expr--*
  262. expr6 .     expr6 ..    string concatenation    *expr-.*
  263.  
  264. expr7 *     expr7 ..    number multiplication    *expr-star*
  265. expr7 /     expr7 ..    number division        *expr-/*
  266. expr7 %     expr7 ..    number modulo        *expr-%*
  267.  
  268. For all, except ".", Strings are converted to Numbers.
  269.  
  270. Note the difference between "+" and ".":
  271. "123" + "456" = 579
  272. "123" . "456" = "123456"
  273.  
  274. When the righthand side of '/' is zero, the result is 0xfffffff.
  275. When the righthand side of '%' is zero, the result is 0.
  276.  
  277.  
  278. expr7                            *expr7*
  279. -----
  280. ! expr7            logical NOT        *expr-!*
  281. - expr7            unary minus        *expr-unary--*
  282. + expr7            unary plus        *expr-unary-+*
  283.  
  284. For '!' non-zero becomes zero, zero becomes one.
  285. For '-' the sign of the number is changed.
  286. For '+' the number is unchanged.
  287.  
  288. A String will be converted to a Number first.
  289.  
  290. These three can be repeated and mixed.  Examples:
  291. !-1        == 0
  292. !!8        == 1
  293. --9        == 9
  294.  
  295.  
  296. expr8                            *expr8*
  297. -----
  298. expr9[expr1]        index in String        *expr-[]* *E111*
  299.  
  300. This results in a String that contains the expr1'th single character from
  301. expr9.  expr9 is used as a String, expr1 as a Number.
  302.  
  303. Note that index zero gives the first character.  This is like it works in C.
  304. Careful: text column numbers start with one!  Example, to get the character
  305. under the cursor: >
  306. :let c = getline(line("."))[col(".") - 1]
  307.  
  308. If the length of the String is less than the index, the result is an empty
  309. String.
  310.  
  311.                         *expr9*
  312. number
  313. ------
  314. number            number constant        *expr-number*
  315.  
  316. Decimal, Hexadecimal (starting with 0x or 0X), or Octal (starting with 0).
  317.  
  318.  
  319. string                            *expr-string* *E114*
  320. ------
  321. "string"        string constant        *expr-quote*
  322.  
  323. Note that double quotes are used.
  324.  
  325. A string constant accepts these special characters:
  326. \...    three-digit octal number (e.g., "\316")
  327. \..    two-digit octal number (must be followed by non-digit)
  328. \.    one-digit octal number (must be followed by non-digit)
  329. \x..    two-character hex number (e.g., "\x1f")
  330. \x.    one-character hex number (must be followed by non-hex)
  331. \X..    same as \x..
  332. \X.    same as \x.
  333. \b    backspace <BS>
  334. \e    escape <Esc>
  335. \f    formfeed <FF>
  336. \n    newline <NL>
  337. \r    return <CR>
  338. \t    tab <Tab>
  339. \\    backslash
  340. \"    double quote
  341. \<xxx>    Special key named "xxx".  e.g. "\<C-W>" for CTRL-W.
  342.  
  343. Note that "\000" and "\x00" force the end of the string.
  344.  
  345.  
  346. literal-string                        *literal-string* *E115*
  347. ---------------
  348. 'string'        literal string constant        *expr-'*
  349.  
  350. Note that single quotes are used.
  351.  
  352. This string is taken literally.  No backslashes are removed or have a special
  353. meaning.  A literal-string cannot contain a single quote.  Use a normal string
  354. for that.
  355.  
  356.  
  357. option                        *expr-option* *E112* *E113*
  358. ------
  359. &option            option value
  360.  
  361. Any option name can be used here.  See |options|.  This sets the buffer-local
  362. or window-local value if there is one.
  363.  
  364.  
  365. register                        *expr-register*
  366. --------
  367. @r            contents of register 'r'
  368.  
  369. The result is the contents of the named register, as a single string.
  370. Newlines are inserted where required.  To get the contents of the unnamed
  371. register use @@.  The '=' register can not be used here.  See |registers| for
  372. an explanation of the available registers.
  373.  
  374.  
  375. nesting                            *expr-nesting* *E110*
  376. -------
  377. (expr1)            nested expression
  378.  
  379.  
  380. environment variable                    *expr-env*
  381. --------------------
  382. $VAR            environment variable
  383.  
  384. The String value of any environment variable.  When it is not defined, the
  385. result is an empty string.
  386.                         *expr-env-expand*
  387. Note that there is a difference between using $VAR directly and using
  388. expand("$VAR").  Using it directly will only expand environment variables that
  389. are known inside the current Vim session.  Using expand() will first try using
  390. the environment variables known inside the current Vim session.  If that
  391. fails, a shell will be used to expand the variable.  This can be slow, but it
  392. does expand all variables that the shell knows about.  Example: >
  393. :echo $version
  394. :echo expand("$version")
  395. The first one probably doesn't echo anything, the second echoes the $version
  396. variable (if your shell supports it).
  397.  
  398.  
  399. internal variable                    *expr-variable*
  400. -----------------
  401. variable        internal variable
  402. See below |internal-variables|.
  403.  
  404.  
  405. function call        *expr-function* *E116* *E117* *E118* *E119* *E120*
  406. -------------
  407. function(expr1, ...)    function call
  408. See below |functions|.
  409.  
  410.  
  411. ==============================================================================
  412. 3. Internal variable                *internal-variables* *E121*
  413.  
  414. An internal variable name can be made up of letters, digits and '_'.  But it
  415. cannot start with a digit.  It's also possible to use curly braces, see
  416. |curly-braces-names|.
  417.  
  418. An internal variable is created with the ":let" command |:let|.
  419. An internal variable is destroyed with the ":unlet" command |:unlet|.
  420. Using a name that isn't an internal variable, or an internal variable that has
  421. been destroyed, results in an error.
  422.  
  423. There are several name spaces for variables.  Which one is to be used is
  424. specified by what is prepended::
  425.  
  426.     (nothing) In a function: local to a function; Otherwise: global
  427. |buffer-variable|    b:      Local to the current buffer.
  428. |window-variable|    w:      Local to the current window.
  429. |global-variable|    g:      Global.
  430. |local-variable|     l:      Local to a function.
  431. |script-variable|    s:      Local to a |:source|'ed Vim script.
  432. |function-argument|  a:      Function argument (only inside a function).
  433. |vim-variable|       v:      Global, predefined by Vim.
  434.  
  435.                         *buffer-variable* *b:var*
  436. A variable name that is preceded with "b:" is local to the current buffer.
  437. Thus you can have several "b:foo" variables, one for each buffer.
  438. This kind of variable is deleted when the buffer is unloaded.  If you want to
  439. keep it, avoid that the buffer is unloaded by setting the 'hidden' option.
  440.  
  441. One local buffer variable is predefined:
  442.                     *b:changedtick-variable* *changetick*
  443. b:changedtick    The total number of changes to the current buffer.  It is
  444.         incremented for each change.  An undo command is also a change
  445.         in this case.  This can be used to perform an action only when
  446.         the buffer has changed.  Example: >
  447.             :if my_changedtick != b:changedtick
  448.             :   let my_changedtick = b:changedtick
  449.             :   call My_Update()
  450.             :endif
  451. <
  452.                         *window-variable* *w:var*
  453. A variable name that is preceded with "w:" is local to the current window.  It
  454. is deleted when the window is closed.
  455.  
  456.                         *global-variable* *g:var*
  457. Inside functions global variables are accessed with "g:".  Omitting this will
  458. access a variable local to a function.  But "g:" can also be used in any other
  459. place if you like.
  460.  
  461.                         *local-variable* *l:var*
  462. Inside functions local variables are accessed without prepending anything.
  463. But you can also prepend "l:" if you like.
  464.  
  465.                         *script-variable* *s:var*
  466. In a Vim script variables starting with "s:" can be used.  They cannot be
  467. accessed from outside of the scripts, thus are local to the script.
  468.  
  469. They can be used in:
  470. - commands executed while the script is sourced
  471. - functions defined in the script
  472. - autocommands defined in the script
  473. - functions and autocommands defined in functions and autocommands which were
  474.   defined in the script (recursively)
  475. - user defined commands defined in the script
  476. Thus not in:
  477. - other scripts sourced from this one
  478. - mappings
  479. - etc.
  480.  
  481. script variables can be used to avoid conflicts with global variable names.
  482. An example that works: >
  483.  
  484.     let s:counter = 0
  485.     function MyCounter()
  486.       let s:counter = s:counter + 1
  487.       echo s:counter
  488.     endfunction
  489.     command Tick call MyCounter()
  490.  
  491. And an example that does NOT work: >
  492.  
  493.     let s:counter = 0
  494.     command Tick let s:counter = s:counter + 1 | echo s:counter
  495.  
  496. When the ":Tick" command is executed outside the script, the s:counter
  497. variable will not be available.  In the previous example, calling the
  498. MyCounter() function sets the context for script variables to where the
  499. function was defined, then s:counter can be used.
  500. The script variables are also available when a function is defined inside a
  501. function that is defined in a script.  Example: >
  502.  
  503.     let s:counter = 0
  504.     function StartCounting(incr)
  505.       if a:incr
  506.         function MyCounter()
  507.           let s:counter = s:counter + 1
  508.         endfunction
  509.       else
  510.         function MyCounter()
  511.           let s:counter = s:counter - 1
  512.         endfunction
  513.       endif
  514.     endfunction
  515.  
  516. This defines the MyCounter() function either for counting up or counting down
  517. when calling StartCounting().  It doesn't matter from where StartCounting() is
  518. called, the s:counter variable will be accessible in MyCounter().
  519.  
  520. When the same script is sourced again it will use the same script variables.
  521. They will remain valid as long as Vim is running.  This can be used to
  522. maintain a counter: >
  523.  
  524.     if !exists("s:counter")
  525.       let s:counter = 1
  526.       echo "script executed for the first time"
  527.     else
  528.       let s:counter = s:counter + 1
  529.       echo "script executed " . s:counter . " times now"
  530.     endif
  531.  
  532. Note that this means that filetype plugins don't get a different set of script
  533. variables for each buffer.  Use local buffer variables instead |b:var|.
  534.  
  535.  
  536. Predefined Vim variables:            *vim-variable* *v:var*
  537.  
  538.             *v:charconvert_from* *charconvert_from-variable*
  539. v:charconvert_from
  540.         The name of the character encoding of a file to be converted.
  541.         Only valid while evaluating the 'charconvert' option.
  542.  
  543.             *v:charconvert_to* *charconvert_to-variable*
  544. v:charconvert_to
  545.         The name of the character encoding of a file after conversion.
  546.         Only valid while evaluating the 'charconvert' option.
  547.  
  548.                     *v:fname_in* *fname_in-variable*
  549. v:fname_in    The name of the input file.  Only valid while evaluating:
  550.             option        used for ~
  551.             'charconvert'    file to be converted
  552.             'diffexpr'    original file
  553.             'patchexpr'    original file
  554.             'printexpr'    file to be printed
  555.  
  556.                     *v:fname_out* *fname_out-variable*
  557. v:fname_out    The name of the output file.  Only valid while
  558.         evaluating:
  559.             option        used for ~
  560.             'charconvert'    resulting converted file (*)
  561.             'diffexpr'    output of diff
  562.             'patchexpr'    resulting patched file
  563.         (*) When doing conversion for a write command (e.g., ":w
  564.         file") it will be equal to v:fname_in.  When doing conversion
  565.         for a read command (e.g., ":e file") it will be a temporary
  566.         file and different from v:fname_in.
  567.  
  568.                     *v:fname_new* *fname_new-variable*
  569. v:fname_new    The name of the new version of the file.  Only valid while
  570.         evaluating 'diffexpr'.
  571.  
  572.                     *v:fname_diff* *fname_diff-variable*
  573. v:fname_diff    The name of the diff (patch) file.  Only valid while
  574.         evaluating 'patchexpr'.
  575.  
  576.                     *v:cmdarg* *cmdarg-variable*
  577. v:cmdarg    This variable is used for two purposes:
  578.         1. The extra arguments given to a file read/write command.
  579.            Currently these are "++enc=" and "++ff=".  This variable is
  580.            set before an autocommand event for a file read/write
  581.            command is triggered.  There is a leading space to make it
  582.            possible to append this variable directly after the
  583.            read/write command.  Note: The "+cmd" argument isn't
  584.            included here, because it will be executed anyway.
  585.         2. When printing a PostScript file with ":hardcopy" this is
  586.            the argument for the ":hardcopy" command.  This can be used
  587.            in 'printexpr'.
  588.  
  589.                     *v:count* *count-variable*
  590. v:count        The count given for the last Normal mode command.  Can be used
  591.         to get the count before a mapping.  Read-only.  Example: >
  592.     :map _x :<C-U>echo "the count is " . v:count<CR>
  593. <        Note: The <C-U> is required to remove the line range that you
  594.         get when typing ':' after a count.
  595.         "count" also works, for backwards compatibility.
  596.  
  597.                     *v:count1* *count1-variable*
  598. v:count1    Just like "v:count", but defaults to one when no count is
  599.         used.
  600.  
  601.                     *v:prevcount* *prevcount-variable*
  602. v:prevcount    The count given for the last but one Normal mode command.
  603.         This is the v:count value of the previous command.  Useful if
  604.         you want to cancel Visual mode and then use the count. >
  605.             :vmap % <Esc>:call MyFilter(v:prevcount)<CR>
  606. <        Read-only.
  607.  
  608.                     *v:errmsg* *errmsg-variable*
  609. v:errmsg    Last given error message.  It's allowed to set this variable.
  610.         Example: >
  611.     :let v:errmsg = ""
  612.     :silent! next
  613.     :if v:errmsg != ""
  614.     :  ... handle error
  615. <        "errmsg" also works, for backwards compatibility.
  616.  
  617.                     *v:folddashes* *folddashes-variable*
  618. v:folddashes    Used for 'foldtext': dashes representing foldlevel of a closed
  619.         fold.
  620.         Read-only. |fold-foldtext|
  621.  
  622.                     *v:foldlevel* *foldlevel-variable*
  623. v:foldlevel    Used for 'foldtext': foldlevel of closed fold.
  624.         Read-only. |fold-foldtext|
  625.  
  626.                     *v:foldend* *foldend-variable*
  627. v:foldend    Used for 'foldtext': last line of closed fold.
  628.         Read-only. |fold-foldtext|
  629.  
  630.                     *v:foldstart* *foldstart-variable*
  631. v:foldstart    Used for 'foldtext': first line of closed fold.
  632.         Read-only. |fold-foldtext|
  633.  
  634.                     *v:progname* *progname-variable*
  635. v:progname    Contains the name (with path removed) with which vim was
  636.         invoked.  Allows you to do special initialisations for "view",
  637.         "evim" etc., or any other name you might symlink to vim.
  638.         Read-only.
  639.  
  640.                         *v:lang* *lang-variable*
  641. v:lang        The current locale setting for messages of the runtime
  642.         environment.  This allows Vim scripts to be aware of the
  643.         current language.  Technical: it's the value of LC_MESSAGES.
  644.         This variable can not be set directly, use the |:language|
  645.         command.
  646.         It can be different from |v:ctype| when messages are desired
  647.         in a different language than what is used for character
  648.         encoding.  See |multi-lang|.
  649.  
  650.                         *v:lc_time* *lc_time-variable*
  651. v:lc_time    The current locale setting for time messages of the runtime
  652.         environment.  This allows Vim scripts to be aware of the
  653.         current language.  Technical: it's the value of LC_TIME.
  654.         This variable can not be set directly, use the |:language|
  655.         command.  See |multi-lang|.
  656.  
  657.                         *v:ctype* *ctype-variable*
  658. v:ctype        The current locale setting for characters of the runtime
  659.         environment.  This allows Vim scripts to be aware of the
  660.         current locale encoding.  Technical: it's the value of
  661.         LC_CTYPE.
  662.         This variable can not be set directly, use the |:language|
  663.         command.
  664.         Normally it's equal to 'encoding', but not always...
  665.         See |multi-lang|.
  666.  
  667.                         *v:lnum* *lnum-variable*
  668. v:lnum        Line number for the 'foldexpr' and 'indentexpr' expressions.
  669.         Only valid while one of these expressions is being evaluated.
  670.         Read-only. |fold-expr| 'indentexpr'
  671.  
  672.                     *v:servername* *servername-variable*
  673. v:servername    The resulting registered |x11-clientserver| name if any.
  674.  
  675.                     *v:shell_error* *shell_error-variable*
  676. v:shell_error    Result of the last shell command.  When non-zero, the last
  677.         shell command had an error.  When zero, there was no problem.
  678.         This only works when the shell returns the error code to Vim.
  679.         The value -1 is often used when the command could not be
  680.         executed.  Read-only.
  681.         Example: >
  682.     :!mv foo bar
  683.     :if v:shell_error
  684.     :  echo 'could not rename "foo" to "bar"!'
  685.     :endif
  686. <        "shell_error" also works, for backwards compatibility.
  687.  
  688.                     *v:statusmsg* *statusmsg-variable*
  689. v:statusmsg    Last given status message.  It's allowed to set this variable.
  690.  
  691.                 *v:termresponse* *termresponse-variable*
  692. v:termresponse    The escape sequence returned by the terminal for the |t_RV|
  693.         termcap entry.  It is set when Vim receives an escape sequence
  694.         that starts with ESC [ or CSI and ends in a 'c', with only
  695.         digits, ';' and '.' in between.
  696.         When this option is set, the TermResponse autocommand event is
  697.         fired, so that you can react to the response from the
  698.         terminal.
  699.         The response from a new xterm is: "<Esc>[ Pp ; Pv ; Pc c".  Pp
  700.         is the terminal type: 0 for vt100 and 1 for vt220.  Pv is the
  701.         patch level (since this was introduced in patch 95, it's
  702.         always 95 or bigger).  Pc is always zero.
  703.         {only when compiled with |+termresponse| feature}
  704.  
  705.                 *v:this_session* *this_session-variable*
  706. v:this_session    Full filename of the last loaded or saved session file.  See
  707.         |:mksession|.  It is allowed to set this variable.  When no
  708.         session file has been saved, this variable is empty.
  709.         "this_session" also works, for backwards compatibility.
  710.  
  711.                     *v:version* *version-variable*
  712. v:version    Version number of Vim: Major version number times 100 plus
  713.         minor version number.  Version 5.0 is 500.  Version 5.1 (5.01)
  714.         is 501.  Read-only.  "version" also works, for backwards
  715.         compatibility.
  716.  
  717.                     *v:warningmsg* *warningmsg-variable*
  718. v:warningmsg    Last given warning message.  It's allowed to set this variable.
  719.  
  720. ==============================================================================
  721. 4. Builtin Functions                    *functions*
  722.  
  723. See |function-list| for a list grouped by what the function is used for.
  724.  
  725. (Use CTRL-] on the function name to jump to the full explanation)
  726.  
  727. USAGE                RESULT    DESCRIPTION    ~
  728.  
  729. append( {lnum}, {string})    Number  append {string} below line {lnum}
  730. argc()                Number    number of files in the argument list
  731. argidx()            Number  current index in the argument list
  732. argv( {nr})            String    {nr} entry of the argument list
  733. browse( {save}, {title}, {initdir}, {default})
  734.                 String    put up a file requester
  735. bufexists( {expr})        Number    TRUE if buffer {expr} exists
  736. buflisted( {expr})        Number  TRUE if buffer {expr} is listed
  737. bufloaded( {expr})        Number  TRUE if buffer {expr} is loaded
  738. bufname( {expr})        String    Name of the buffer {expr}
  739. bufnr( {expr})            Number    Number of the buffer {expr}
  740. bufwinnr( {expr})        Number    window number of buffer {expr}
  741. byte2line( {byte})        Number    line number at byte count {byte}
  742. char2nr( {expr})        Number    ASCII value of first char in {expr}
  743. cindent( {lnum})        Number  C indent for line {lnum}
  744. col( {expr})            Number    column nr of cursor or mark
  745. confirm( {msg}, {choices} [, {default} [, {type}]])
  746.                 Number    number of choice picked by user
  747. cscope_connection( [{num} , {dbpath} [, {prepend}]])
  748.                 Number    checks existence of cscope connection
  749. delete( {fname})        Number    delete file {fname}
  750. did_filetype()            Number    TRUE if FileType autocommand event used
  751. escape( {string}, {chars})    String    escape {chars} in {string} with '\'
  752. eventhandler( )            Number  TRUE if inside an event handler
  753. executable( {expr})        Number    1 if executable {expr} exists
  754. exists( {var})            Number    TRUE if {var} exists
  755. expand( {expr})            String    expand special keywords in {expr}
  756. filereadable( {file})        Number    TRUE if {file} is a readable file
  757. fnamemodify( {fname}, {mods})    String    modify file name
  758. foldclosed( {lnum})        Number  >0 if fold at {lnum} is closed
  759. foldlevel( {lnum})        Number    fold level at {lnum}
  760. foldtext( )            String  line displayed for closed fold
  761. foreground( )            Number    bring the Vim window to the foreground
  762. getchar( [expr])        Number  get one character from the user
  763. getcharmod( )            Number  modifiers for the last typed character
  764. getbufvar( {expr}, {varname})        variable {varname} in buffer {expr}
  765. getcwd()            String    the current working directory
  766. getftime( {fname})        Number    last modification time of file
  767. getfsize( {fname})        Number    size in bytes of file
  768. getline( {lnum})        String    line {lnum} from current buffer
  769. getwinposx()            Number    X coord in pixels of GUI vim window
  770. getwinposy()            Number    Y coord in pixels of GUI vim window
  771. getwinvar( {nr}, {varname}        variable {varname} in window {nr}
  772. glob( {expr}])            String    expand file wildcards in {expr}
  773. globpath( {path}, {expr})    String    do glob({expr}) for all dirs in {path}
  774. has( {feature})            Number    TRUE if feature {feature} supported
  775. hasmapto( {what} [, {mode}])    Number    TRUE if mapping to {what} exists
  776. histadd( {history},{item})    String    add an item to a history
  777. histdel( {history} [, {item}])    String    remove an item from a history
  778. histget( {history} [, {index}])    String    get the item {index} from a history
  779. histnr( {history})        Number    highest index of a history
  780. hlexists( {name})        Number    TRUE if highlight group {name} exists
  781. hlID( {name})            Number    syntax ID of highlight group {name}
  782. hostname()            String    name of the machine vim is running on
  783. indent( {lnum})            Number  indent of line {lnum}
  784. input( {prompt} [, {text}])    String    get input from the user
  785. inputdialog( {prompt} [, {text}]) String  like input() but in a GUI dialog
  786. inputsecret( {prompt} [, {text}]) String  like input() but hiding the text
  787. isdirectory( {directory})    Number    TRUE if {directory} is a directory
  788. libcall( {lib}, {func}, {arg})    String  call {func} in library {lib} with {arg}
  789. libcallnr( {lib}, {func}, {arg})  Number  idem, but return a Number
  790. line( {expr})            Number    line nr of cursor, last line or mark
  791. line2byte( {lnum})        Number    byte count of line {lnum}
  792. lispindent( {lnum})        Number  Lisp indent for line {lnum}
  793. localtime()            Number    current time
  794. maparg( {name}[, {mode}])    String    rhs of mapping {name} in mode {mode}
  795. mapcheck( {name}[, {mode}])    String    check for mappings matching {name}
  796. match( {expr}, {pat}[, {start}])
  797.                 Number    position where {pat} matches in {expr}
  798. matchend( {expr}, {pat}[, {start})
  799.                 Number    position where {pat} ends in {expr}
  800. matchstr( {expr}, {pat}[, {start}])
  801.                 String    match of {pat} in {expr}
  802. mode()                String  current editing mode
  803. nextnonblank( {lnum})        Number    line nr of non-blank line >= {lnum}
  804. nr2char( {expr})        String    single char with ASCII value {expr}
  805. prevnonblank( {lnum})        Number    line nr of non-blank line <= {lnum}
  806. remote_expr( {server}, {string} [, {idvar}])
  807.                 String    send expression
  808. remote_foreground( {server})    Number    bring Vim server to the foreground
  809. remote_peek( {serverid} [, {retvar}])
  810.                 Number    check for reply string
  811. remote_read( {serverid})    String    read reply string
  812. remote_send( {server}, {string} [, {idvar}])
  813.                 String    send key sequence
  814. rename( {from}, {to})        Number  rename (move) file from {from} to {to}
  815. resolve( {filename})        String  get filename a shortcut points to
  816. search( {pattern} [, {flags}])    Number  search for {pattern}
  817. searchpair( {start}, {middle}, {end} [, {flags} [, {skip}]])
  818.                 Number  search for other end of start/end pair
  819. server2client( {serverid}, {string})
  820.                 Number    send reply string
  821. serverlist()            String    get a list of available servers
  822. setbufvar( {expr}, {varname}, {val})    set {varname} in buffer {expr} to {val}
  823. setline( {lnum}, {line})    Number    set line {lnum} to {line}
  824. setwinvar( {nr}, {varname}, {val})    set {varname} in window {nr} to {val}
  825. strftime( {format}[, {time}])    String    time in specified format
  826. stridx( {haystack}, {needle})    Number    first index of {needle} in {haystack}
  827. strlen( {expr})            Number    length of the String {expr}
  828. strpart( {src}, {start}[, {len}])
  829.                 String    {len} characters of {src} at {start}
  830. strridx( {haystack}, {needle})    Number    last index of {needle} in {haystack}
  831. strtrans( {expr})        String    translate string to make it printable
  832. submatch( {nr})            String  specific match in ":substitute"
  833. substitute( {expr}, {pat}, {sub}, {flags})
  834.                 String    all {pat} in {expr} replaced with {sub}
  835. synID( {line}, {col}, {trans})    Number    syntax ID at {line} and {col}
  836. synIDattr( {synID}, {what} [, {mode}])
  837.                 String    attribute {what} of syntax ID {synID}
  838. synIDtrans( {synID})        Number    translated syntax ID of {synID}
  839. system( {expr})            String    output of shell command {expr}
  840. tempname()            String    name for a temporary file
  841. tolower( {expr})        String    the String {expr} switched to lowercase
  842. toupper( {expr})        String    the String {expr} switched to uppercase
  843. type( {name})            Number    type of variable {name}
  844. virtcol( {expr})        Number    screen column of cursor or mark
  845. visualmode()            String    last visual mode used
  846. winbufnr( {nr})            Number    buffer number of window {nr}
  847. wincol()            Number    window column of the cursor
  848. winheight( {nr})        Number    height of window {nr}
  849. winline()            Number    window line of the cursor
  850. winnr()                Number    number of current window
  851. winwidth( {nr})            Number    width of window {nr}
  852.  
  853. append({lnum}, {string})                *append()*
  854.         Append the text {string} after line {lnum} in the current
  855.         buffer.  {lnum} can be zero, to insert a line before the first
  856.         one.  Returns 1 for failure ({lnum} out of range) or 0 for
  857.         success.
  858.  
  859.                             *argc()*
  860. argc()        The result is the number of files in the argument list of the
  861.         current window.  See |arglist|.
  862.  
  863.                             *argidx()*
  864. argidx()    The result is the current index in the argument list.  0 is
  865.         the first file.  argc() - 1 is the last one.  See |arglist|.
  866.  
  867.                             *argv()*
  868. argv({nr})    The result is the {nr}th file in the argument list of the
  869.         current window.  See |arglist|.  "argv(0)" is the first one.
  870.         Example: >
  871.     :let i = 0
  872.     :while i < argc()
  873.     :  let f = substitute(argv(i), '\([. ]\)', '\\&', 'g')
  874.     :  exe 'amenu Arg.' . f . ' :e ' . f . '<CR>'
  875.     :  let i = i + 1
  876.     :endwhile
  877. <
  878.                             *browse()*
  879. browse({save}, {title}, {initdir}, {default})
  880.         Put up a file requester.  This only works when "has("browse")"
  881.         returns non-zero (only in some GUI versions).
  882.         The input fields are:
  883.             {save}    when non-zero, select file to write
  884.             {title}    title for the requester
  885.             {initdir}    directory to start browsing in
  886.             {default}    default file name
  887.         When the "Cancel" button is hit, something went wrong, or
  888.         browsing is not possible, an empty string is returned.
  889.  
  890. bufexists({expr})                    *bufexists()*
  891.         The result is a Number, which is non-zero if a buffer called
  892.         {expr} exists.
  893.         If the {expr} argument is a string it must match a buffer name
  894.         exactly.
  895.         If the {expr} argument is a number buffer numbers are used.
  896.         Unlisted buffers will be found.
  897.         Note that help files are listed by their short name in the
  898.         output of |:buffers|, but bufexists() requires using their
  899.         long name to be able to find them.
  900.         Use "bufexists(0)" to test for the existence of an alternate
  901.         file name.
  902.                             *buffer_exists()*
  903.         Obsolete name: buffer_exists().
  904.  
  905. buflisted({expr})                    *buflisted()*
  906.         The result is a Number, which is non-zero if a buffer called
  907.         {expr} exists and is listed (has the 'buflisted' option set).
  908.         The {expr} argument is used like with bufexists().
  909.  
  910. bufloaded({expr})                    *bufloaded()*
  911.         The result is a Number, which is non-zero if a buffer called
  912.         {expr} exists and is loaded (shown in a window or hidden).
  913.         The {expr} argument is used like with bufexists().
  914.  
  915. bufname({expr})                        *bufname()*
  916.         The result is the name of a buffer, as it is displayed by the
  917.         ":ls" command.
  918.         If {expr} is a Number, that buffer number's name is given.
  919.         Number zero is the alternate buffer for the current window.
  920.         If {expr} is a String, it is used as a regexp pattern to match
  921.         with the buffer names.  This is always done like 'magic' is
  922.         set and 'cpoptions' is empty.  When there is more than one
  923.         match an empty string is returned.  "" or "%" can be used for
  924.         the current buffer, "#" for the alternate buffer.
  925.         If the {expr} is a String, but you want to use it as a buffer
  926.         number, force it to be a Number by adding zero to it: >
  927.             :echo bufname("3" + 0)
  928. <        If the buffer doesn't exist, or doesn't have a name, an empty
  929.         string is returned. >
  930.     bufname("#")        alternate buffer name
  931.     bufname(3)        name of buffer 3
  932.     bufname("%")        name of current buffer
  933.     bufname("file2")    name of buffer where "file2" matches.
  934. <                            *buffer_name()*
  935.         Obsolete name: buffer_name().
  936.  
  937.                             *bufnr()*
  938. bufnr({expr})    The result is the number of a buffer, as it is displayed by
  939.         the ":ls" command.  For the use of {expr}, see |bufname()|
  940.         above.  If the buffer doesn't exist, -1 is returned.
  941.         bufnr("$") is the last buffer: >
  942.     :let last_buffer = bufnr("$")
  943. <        The result is a Number, which is the highest buffer number
  944.         of existing buffers.  Note that not all buffers with a smaller
  945.         number necessarily exist, because ":bwipeout" may have removed
  946.         them.  Use bufexists() to test for the existence of a buffer.
  947.                             *buffer_number()*
  948.         Obsolete name: buffer_number().
  949.                             *last_buffer_nr()*
  950.         Obsolete name for bufnr("$"): last_buffer_nr().
  951.  
  952. bufwinnr({expr})                    *bufwinnr()*
  953.         The result is a Number, which is the number of the first
  954.         window associated with buffer {expr}.  For the use of {expr},
  955.         see |bufname()| above.  If buffer {expr} doesn't exist or
  956.         there is no such window, -1 is returned.  Example: >
  957.     echo "A window containing buffer 1 is " . (bufwinnr(1))
  958. <
  959. byte2line({byte})                    *byte2line()*
  960.         Return the line number that contains the character at byte
  961.         count {byte} in the current buffer.  This includes the
  962.         end-of-line character, depending on the 'fileformat' option
  963.         for the current buffer.  The first character has byte count
  964.         one.
  965.         Also see |line2byte()|, |go| and |:goto|.
  966.         {not available when compiled without the |+byte_offset|
  967.         feature}
  968.  
  969. char2nr({expr})                        *char2nr()*
  970.         Return ASCII value of the first char in {expr}.  Examples: >
  971.             char2nr(" ")        returns 32
  972.             char2nr("ABC")        returns 65
  973. <
  974. cindent({lnum})                        *cindent()*
  975.         Get the amount of indent for line {lnum} according the C
  976.         indenting rules, as with 'cindent'.
  977.         The indent is counted in spaces, the value of 'tabstop' is
  978.         relevant.  {lnum} is used just like in |getline()|.
  979.         When {lnum} is invalid or Vim was not compiled the |+cindent|
  980.         feature, -1 is returned.
  981.  
  982.                             *col()*
  983. col({expr})    The result is a Number, which is the column of the file
  984.         position given with {expr}.  The accepted positions are:
  985.             .        the cursor position
  986.             $        the end of the cursor line (the result is the
  987.                 number of characters in the cursor line plus one)
  988.             'x        position of mark x (if the mark is not set, 0 is
  989.                 returned)
  990.         Note that only marks in the current file can be used.
  991.         Examples: >
  992.             col(".")        column of cursor
  993.             col("$")        length of cursor line plus one
  994.             col("'t")        column of mark t
  995.             col("'" . markname)    column of mark markname
  996. <        The first column is 1.  0 is returned for an error.
  997.  
  998.                             *confirm()*
  999. confirm({msg}, {choices} [, {default} [, {type}]])
  1000.         Confirm() offers the user a dialog, from which a choice can be
  1001.         made.  It returns the number of the choice.  For the first
  1002.         choice this is 1.
  1003.         Note: confirm() is only supported when compiled with dialog
  1004.         support, see |+dialog_con| and |+dialog_gui|.
  1005.         {msg} is displayed in a |dialog| with {choices} as the
  1006.         alternatives.
  1007.         {msg} is a String, use '\n' to include a newline.  Only on
  1008.         some systems the string is wrapped when it doesn't fit.
  1009.         {choices} is a String, with the individual choices separated
  1010.         by '\n', e.g. >
  1011.             confirm("Save changes?", "&Yes\n&No\n&Cancel")
  1012. <        The letter after the '&' is the shortcut key for that choice.
  1013.         Thus you can type 'c' to select "Cancel".  The shorcut does
  1014.         not need to be the first letter: >
  1015.             confirm("file has been modified", "&Save\nSave &All")
  1016. <        For the console, the first letter of each choice is used as
  1017.         the default shortcut key.
  1018.         The optional {default} argument is the number of the choice
  1019.         that is made if the user hits <CR>.  Use 1 to make the first
  1020.         choice the default one.  Use 0 to not set a default.  If
  1021.         {default} is omitted, 0 is used.
  1022.         The optional {type} argument gives the type of dialog.  This
  1023.         is only used for the icon of the Win32 GUI.  It can be one of
  1024.         these values: "Error", "Question", "Info", "Warning" or
  1025.         "Generic".  Only the first character is relevant.  When {type}
  1026.         is omitted, "Generic" is used.
  1027.         If the user aborts the dialog by pressing <Esc>, CTRL-C,
  1028.         or another valid interrupt key, confirm() returns 0.
  1029.  
  1030.         An example: >
  1031.    :let choice = confirm("What do you want?", "&Apples\n&Oranges\n&Bananas", 2)
  1032.    :if choice == 0
  1033.    :    echo "make up your mind!"
  1034.    :elseif choice == 3
  1035.    :    echo "tasteful"
  1036.    :else
  1037.    :    echo "I prefer bananas myself."
  1038.    :endif
  1039. <        In a GUI dialog, buttons are used.  The layout of the buttons
  1040.         depends on the 'v' flag in 'guioptions'.  If it is included,
  1041.         the buttons are always put vertically.  Otherwise,  confirm()
  1042.         tries to put the buttons in one horizontal line.  If they
  1043.         don't fit, a vertical layout is used anyway.  For some systems
  1044.         the horizontal layout is always used.
  1045.  
  1046.                             *cscope_connection()*
  1047. cscope_connection([{num} , {dbpath} [, {prepend}]])
  1048.         Checks for the existence of a |cscope| connection.  If no
  1049.         parameters are specified, then the function returns:
  1050.             0, if cscope was not available (not compiled in), or
  1051.                if there are no cscope connections;
  1052.             1, if there is at least one cscope connection.
  1053.  
  1054.         If parameters are specified, then the value of {num}
  1055.         determines how existence of a cscope connection is checked:
  1056.  
  1057.         {num}    Description of existence check
  1058.         -----    ------------------------------
  1059.         0    Same as no parameters (e.g., "cscope_connection()").
  1060.         1    Ignore {prepend}, and use partial string matches for
  1061.             {dbpath}.
  1062.         2    Ignore {prepend}, and use exact string matches for
  1063.             {dbpath}.
  1064.         3    Use {prepend}, use partial string matches for both
  1065.             {dbpath} and {prepend}.
  1066.         4    Use {prepend}, use exact string matches for both
  1067.             {dbpath} and {prepend}.
  1068.  
  1069.         Note: All string comparisons are case sensitive!
  1070.  
  1071.         Examples.  Suppose we had the following (from ":cs show"): >
  1072.  
  1073.   # pid    database name            prepend path
  1074.   0 27664  cscope.out                /usr/local
  1075. <
  1076.         Invokation                    Return Val ~
  1077.         ----------                    ---------- >
  1078.         cscope_connection()                    1
  1079.         cscope_connection(1, "out")                1
  1080.         cscope_connection(2, "out")                0
  1081.         cscope_connection(3, "out")                0
  1082.         cscope_connection(3, "out", "local")            1
  1083.         cscope_connection(4, "out")                0
  1084.         cscope_connection(4, "out", "local")            0
  1085.         cscope_connection(4, "cscope.out", "/usr/local")    1
  1086. <
  1087.                             *delete()*
  1088. delete({fname})    Deletes the file by the name {fname}.  The result is a Number,
  1089.         which is 0 if the file was deleted successfully, and non-zero
  1090.         when the deletion failed.
  1091.  
  1092.                             *did_filetype()*
  1093. did_filetype()    Returns non-zero when autocommands are being executed and the
  1094.         FileType event has been triggered at least once.  Can be used
  1095.         to avoid triggering the FileType event again in the scripts
  1096.         that detect the file type. |FileType|
  1097.         When editing another file, the counter is reset, thus this
  1098.         really checks if the FileType event has been triggered for the
  1099.         current buffer.  This allows an autocommand that starts
  1100.         editing another buffer to set 'filetype' and load a sytnax
  1101.         file.
  1102.  
  1103. escape({string}, {chars})                *escape()*
  1104.         Escape the characters in {chars} that occur in {string} with a
  1105.         backslash.  Example: >
  1106.             :echo escape('c:\program files\vim', ' \')
  1107. <        results in: >
  1108.             c:\\program\ files\\vim
  1109. <
  1110. eventhandler()                        *eventhandler()*
  1111.         Returns 1 when inside an event handler.  This means
  1112.         interactive commands cannot be used.  Otherwise zero is
  1113.         returned.
  1114.  
  1115. executable({expr})                    *executable()*
  1116.         This function checks if an executable with the name {expr}
  1117.         exists.  {expr} must be the name of the program without any
  1118.         arguments.  executable() uses the normal $PATH.
  1119.         The result is a Number:
  1120.             1    exists
  1121.             0    does not exist
  1122.             -1    not implemented on this system
  1123.  
  1124.                             *exists()*
  1125. exists({expr})    The result is a Number, which is non-zero if {var} is defined,
  1126.         zero otherwise.  The {expr} argument is a string, which
  1127.         contains one of these:
  1128.             &option-name    Vim option
  1129.             $ENVNAME    environment variable (could also be
  1130.                     done by comparing with an empty
  1131.                     string)
  1132.             *funcname    built-in function (see |functions|)
  1133.                     or user defined function (see
  1134.                     |user-functions|).
  1135.             varname        internal variable (see
  1136.                     |internal-variables|).
  1137.             :cmdname    Ex command, both built-in and user
  1138.                     commands |:command|
  1139.                     returns:
  1140.                     1  for match with start of a command
  1141.                     2  full match with a command
  1142.                     3  matches several user commands
  1143.             #event        autocommand defined for this event
  1144.             #event#pattern    autocommand defined for this event and
  1145.                     pattern (the pattern is taken
  1146.                     literally and compared to the
  1147.                     autocommand patterns character by
  1148.                     character)
  1149.  
  1150.         Examples: >
  1151.             exists("&shortname")
  1152.             exists("$HOSTNAME")
  1153.             exists("*strftime")
  1154.             exists("bufcount")
  1155.             exists(":Make")
  1156.             exists("#CursorHold");
  1157.             exists("#BufReadPre#*.gz")
  1158. <        There must be no space between the symbol (&/$/*/#) and the
  1159.         name.
  1160.         Note that the argument must be a string, not the name of the
  1161.         variable itself!  For example: >
  1162.             exists(bufcount)
  1163. <        This doesn't check for existence of the "bufcount" variable,
  1164.         but gets the contents of "bufcount", and checks if that
  1165.         exists.
  1166.  
  1167. expand({expr} [, {flag}])                *expand()*
  1168.         Expand wildcards and the following special keywords in {expr}.
  1169.         The result is a String.
  1170.  
  1171.         When there are several matches, they are separated by <NL>
  1172.         characters.  [Note: in version 5.0 a space was used, which
  1173.         caused problems when a file name contains a space]
  1174.  
  1175.         If the expansion fails, the result is an empty string.  A name
  1176.         for a non-existing file is not included.
  1177.  
  1178.         When {expr} starts with '%', '#' or '<', the expansion is done
  1179.         like for the |cmdline-special| variables with their associated
  1180.         modifiers.  Here is a short overview:
  1181.  
  1182.             %        current file name
  1183.             #        alternate file name
  1184.             #n        alternate file name n
  1185.             <cfile>        file name under the cursor
  1186.             <afile>        autocmd file name
  1187.             <abuf>        autocmd buffer number
  1188.             <amatch>    autocmd matched name
  1189.             <sfile>        sourced script file name
  1190.             <cword>        word under the cursor
  1191.             <cWORD>        WORD under the cursor
  1192.             <client>    The {serverid} of the las
  1193.         Modifiers:
  1194.             :p        expand to full path
  1195.             :h        head (last path component removed)
  1196.             :t        tail (last path component only)
  1197.             :r        root (one extension removed)
  1198.             :e        extension only
  1199.  
  1200.         Example: >
  1201.             :let &tags = expand("%:p:h") . "/tags"
  1202. <        Note that when expanding a string that starts with '%', '#' or
  1203.         '<', any following text is ignored.  This does NOT work: >
  1204.             :let doesntwork = expand("%:h.bak")
  1205. <        Use this: >
  1206.             :let doeswork = expand("%:h") . ".bak"
  1207. <        Also note that expanding "<cfile>" and others only returns the
  1208.         referenced file name without further expansion.  If "<cfile>"
  1209.         is "~/.cshrc", you need to do another expand() to have the
  1210.         "~/" expanded into the path of the home directory: >
  1211.             :echo expand(expand("<cfile>"))
  1212. <
  1213.         There cannot be white space between the variables and the
  1214.         following modifier.  The |fnamemodify()| function can be used
  1215.         to modify normal file names.
  1216.  
  1217.         When using '%' or '#', and the current or alternate file name
  1218.         is not defined, an empty string is used.  Using "%:p" in a
  1219.         buffer with no name, results in the current directory, with a
  1220.         '/' added.
  1221.  
  1222.         When {expr} does not start with '%', '#' or '<', it is
  1223.         expanded like a file name is expanded on the command line.
  1224.         'suffixes' and 'wildignore' are used, unless the optional
  1225.         {flag} argument is given and it is non-zero.
  1226.  
  1227.         Expand() can also be used to expand variables and environment
  1228.         variables that are only known in a shell.  But this can be
  1229.         slow, because a shell must be started.  See |expr-env-expand|.
  1230.  
  1231.         See |glob()| for finding existing files.  See |system()| for
  1232.         getting the raw output of an external command.
  1233.  
  1234. expandpath({expr}, {pathlist})                *expandpath()*
  1235.         Find all matches for {expr} in each element of {pathlist}.
  1236.         Each match is followed by a <NL>.  Example: >
  1237.             let list = expandpath("colors/*.vim", &runtimepath)
  1238. <        This gets a list of the color scheme files in 'runtimepath'.
  1239.         {pathlist} must be a comma separated list of paths.
  1240.         When there are no matches an empty string is returned.
  1241.  
  1242.  
  1243. filereadable({file})                    *filereadable()*
  1244.         The result is a Number, which is TRUE when a file with the
  1245.         name {file} exists, and can be read.  If {file} doesn't exist,
  1246.         or is a directory, the result is FALSE.  {file} is any
  1247.         expression, which is used as a String.
  1248.                             *file_readable()*
  1249.         Obsolete name: file_readable().
  1250.  
  1251. filewritable({file})                    *filewritable()*
  1252.         The result is a Number, which is 1 when a file with the
  1253.         name {file} exists, and can be written.  If {file} doesn't
  1254.         exist, or is not writable, the result is 0.  If (file) is a
  1255.         directory, and we can write to it, the result is 2.
  1256.  
  1257. fnamemodify({fname}, {mods})                *fnamemodify()*
  1258.         Modify file name {fname} according to {mods}.  {mods} is a
  1259.         string of characters like it is used for file names on the
  1260.         command line.  See |filename-modifiers|.
  1261.         Example: >
  1262.             :echo fnamemodify("main.c", ":p:h")
  1263. <        results in: >
  1264.             /home/mool/vim/vim/src
  1265. <        Note: Environment variables and "~" don't work in {fname}, use
  1266.         |expand()| first then.
  1267.  
  1268. foldclosed({lnum})                    *foldclosed()*
  1269.         The result is a Number.  If the line {lnum} is in a closed
  1270.         fold, the result is the number of the first line in that fold.
  1271.         If the line {lnum} is not in a closed fold, -1 is returned.
  1272.  
  1273. foldclosedend({lnum})                    *foldclosedend()*
  1274.         The result is a Number.  If the line {lnum} is in a closed
  1275.         fold, the result is the number of the last line in that fold.
  1276.         If the line {lnum} is not in a closed fold, -1 is returned.
  1277.  
  1278. foldlevel({lnum})                    *foldlevel()*
  1279.         The result is a Number, which is the foldlevel of line {lnum}
  1280.         in the current buffer.  For nested folds the deepest level is
  1281.         returned.  If there is no fold at line {lnum}, zero is
  1282.         returned.  It doesn't matter if the folds are open or closed.
  1283.         When used while updating folds (from 'foldexpr') -1 is
  1284.         returned for lines where folds are still to be updated and the
  1285.         foldlevel is unknown.
  1286.  
  1287.                             *foldtext()*
  1288. foldtext()    Returns a String, to be displayed for a closed fold.  This is
  1289.         the default function used for the 'foldtext' option and should
  1290.         only be called from evaluating 'foldtext'.  It uses the
  1291.         |v:foldstart|, |v:foldend| and |v:folddashes| variables.
  1292.         The returned string looks like this: >
  1293.             +-- 45 lines: abcdef
  1294. <        The number of dashes depends on the foldlevel.  The "45" is
  1295.         the number of lines in the fold.  "abcdef" is the text in the
  1296.         first non-blank line of the fold.  Leading white space, "//"
  1297.         or "/*" and the text from the 'foldmarker' and 'commentstring'
  1298.         options is removed.
  1299.         {not available when compiled without the |+folding| feature}
  1300.  
  1301.                             *foreground()*
  1302. foreground()    Move the Vim window to the foreground.  Useful when sent from
  1303.         a client to a Vim server. |remote_send()|
  1304.         On Win32 systems this might not work, the OS does not always
  1305.         allow a window to bring itself to the foreground.  Use
  1306.         |remote_foreground()| instead.
  1307.         {only in the Win32, Athena, Motif and GTK GUI versions and the
  1308.         Win32 console version}
  1309.  
  1310. getchar([expr])                        *getchar()*
  1311.         Get a single character from the user.  If it is an 8-bit
  1312.         character, the result is a number.  Otherwise a String is
  1313.         returned with the encoded character.
  1314.         If [expr] is omitted, wait until a character is available.
  1315.         If [expr] is 0, only get a character when one is available.
  1316.         If [expr] is 1, only check if a character is available, it is
  1317.                 not consumed.  If a normal character is
  1318.                 available, it is returned, otherwise a
  1319.                 non-zero value is returned.
  1320.         If a character available, it is returned as a Number.  Use
  1321.         nr2char() to convert it to a String.
  1322.         The returned value is negative for special keys.
  1323.         The returned value is zero if no character is available.
  1324.         There is no prompt, you will somehow have to make clear to the
  1325.         user that a character has to be typed.
  1326.         There is no mapping for the character.
  1327.         Key codes are replaced, thus when the user presses the <Del>
  1328.         key you get the code for the <Del> key, not the raw character
  1329.         sequence.  Examples: >
  1330.             getchar() == "\<Del>"
  1331.             getchar() == "\<S-Left>"
  1332. <        This example redefines "f" to ignore case: >
  1333.             :nmap f :call FindChar()<CR>
  1334.             :function FindChar()
  1335.             :  let c = nr2char(getchar())
  1336.             :  while col('.') < col('$') - 1
  1337.             :    normal l
  1338.             :    if getline('.')[col('.') - 1] ==? c
  1339.             :      break
  1340.             :    endif
  1341.             :  endwhile
  1342.             :endfunction
  1343.  
  1344. getcharmod()                        *getcharmod()*
  1345.         The result is a Number which is the state of the modifiers for
  1346.         the last obtained character with getchar() or in another way.
  1347.         These values are added together:
  1348.             2    shift
  1349.             4    control
  1350.             8    alt (meta)
  1351.             16    mouse double click
  1352.             32    mouse triple click
  1353.             64    mouse quadruple click
  1354.             128    Macintosh only: command
  1355.  
  1356. getbufvar({expr}, {varname})                *getbufvar()*
  1357.         The result is the value of option or local buffer variable
  1358.         {varname} in buffer {expr}.
  1359.         This also works for a global or local window option, but it
  1360.         doesn't work for a global or local window variable.
  1361.         For the use of {expr}, see |bufname()| above.
  1362.         Note that the name without "b:" must be used.
  1363.         Examples: >
  1364.             :let bufmodified = getbufvar(1, "&mod")
  1365.             :echo "todo myvar = " . getbufvar("todo", "myvar")
  1366. <
  1367.                             *getcwd()*
  1368. getcwd()    The result is a String, which is the name of the current
  1369.         working directory.
  1370.  
  1371. getftime({fname})                    *getftime()*
  1372.         The result is a Number, which is the last modification time of
  1373.         the given file {fname}.  The value is measured as seconds
  1374.         since 1st Jan 1970, and may be passed to strftime().  See also
  1375.         |localtime()| and |strftime()|.
  1376.         If the file {fname} can't be found -1 is returned.
  1377.  
  1378. getfsize({fname})                    *getfsize()*
  1379.         The result is a Number, which is the size in bytes of the
  1380.         given file {fname}.
  1381.         If {fname} is a directory, 0 is returned.
  1382.         If the file {fname} can't be found, -1 is returned.
  1383.  
  1384.                             *getline()*
  1385. getline({lnum}) The result is a String, which is line {lnum} from the current
  1386.         buffer.  Example: >
  1387.             getline(1)
  1388. <        When {lnum} is a String that doesn't start with a
  1389.         digit, line() is called to translate the String into a Number.
  1390.         To get the line under the cursor: >
  1391.             getline(".")
  1392. <        When {lnum} is smaller than 1 or bigger than the number of
  1393.         lines in the buffer, an empty string is returned.
  1394.  
  1395.                             *getwinposx()*
  1396. getwinposx()    The result is a Number, which is the X coordinate in pixels of
  1397.         the left hand side of the GUI vim window.  The result will be
  1398.         -1 if the information is not available.
  1399.  
  1400.                             *getwinposy()*
  1401. getwinposy()    The result is a Number, which is the Y coordinate in pixels of
  1402.         the top of the GUI vim window.  The result will be -1 if the
  1403.         information is not available.
  1404.  
  1405. getwinvar({nr}, {varname})                *getwinvar()*
  1406.         The result is the value of option or local window variable
  1407.         {varname} in window {nr}.
  1408.         This also works for a global or local buffer option, but it
  1409.         doesn't work for a global or local buffer variable.
  1410.         Note that the name without "w:" must be used.
  1411.         Examples: >
  1412.             :let list_is_on = getwinvar(2, '&list')
  1413.             :echo "myvar = " . getwinvar(1, 'myvar')
  1414. <
  1415.                             *glob()*
  1416. glob({expr})    Expand the file wildcards in {expr}.  The result is a String.
  1417.         When there are several matches, they are separated by <NL>
  1418.         characters.
  1419.         If the expansion fails, the result is an empty string.
  1420.         A name for a non-existing file is not included.
  1421.  
  1422.         For most systems backticks can be used to get files names from
  1423.         any external command.  Example: >
  1424.             :let tagfiles = glob("`find . -name tags -print`")
  1425.             :let &tags = substitute(tagfiles, "\n", ",", "g")
  1426. <        The result of the program inside the backticks should be one
  1427.         item per line.  Spaces inside an item are allowed.
  1428.  
  1429.         See |expand()| for expanding special Vim variables.  See
  1430.         |system()| for getting the raw output of an external command.
  1431.  
  1432. globpath({path}, {expr})                *globpath()*
  1433.         Perform glob() on all directories in {path} and concatenate
  1434.         the results.  Example: >
  1435.             :echo globpath(&rtp, "syntax/c.vim")
  1436. <        {path} is a comma-separated list of directory names.  Each
  1437.         directory name is prepended to {expr} and expanded like with
  1438.         glob().  A path separator is inserted when needed.
  1439.         If the expansion fails for one of the directories, there is no
  1440.         error message.
  1441.  
  1442.                             *has()*
  1443. has({feature})    The result is a Number, which is 1 if the feature {feature} is
  1444.         supported, zero otherwise.  The {feature} argument is a
  1445.         string.  See |feature-list| below.
  1446.  
  1447. hasmapto({what} [, {mode}])                *hasmapto()*
  1448.         The result is a Number, which is 1 if there is a mapping that
  1449.         contains {what} in the rhs (what it is mapped to) and this
  1450.         mapping exists in one of the modes indicated by {mode}.
  1451.         Both the global mappings and the mappings local to the current
  1452.         buffer are checked for a match.
  1453.         If no matching mapping is found 0 is returned.
  1454.         The following characters are recognized in {mode}:
  1455.             n    Normal mode
  1456.             v    Visual mode
  1457.             o    Operator-pending mode
  1458.             i    Insert mode
  1459.             l    Language-Argument ("r", "f", "t", etc.)
  1460.             c    Command-line mode
  1461.         When {mode} is omitted, "nvo" is used.
  1462.  
  1463.         This function is useful to check if a mapping already exists
  1464.         to a function in a Vim script.  Example: >
  1465.             :if !hasmapto('\ABCdoit')
  1466.             :   map <Leader>d \ABCdoit
  1467.             :endif
  1468. <        This installs the mapping to "\ABCdoit" only if there isn't
  1469.         already a mapping to "\ABCdoit".
  1470.  
  1471. histadd({history}, {item})                *histadd()*
  1472.         Add the String {item} to the history {history} which can be
  1473.         one of:                    *hist-names*
  1474.             "cmd"     or ":"      command line history
  1475.             "search" or "/"   search pattern history
  1476.             "expr"   or "="   typed expression history
  1477.             "input"  or "@"      input line history
  1478.         If {item} does already exist in the history, it will be
  1479.         shifted to become the newest entry.
  1480.         The result is a Number: 1 if the operation was successful,
  1481.         otherwise 0 is returned.
  1482.  
  1483.         Example: >
  1484.             :call histadd("input", strftime("%Y %b %d"))
  1485.             :let date=input("Enter date: ")
  1486. <
  1487. histdel({history} [, {item}])                *histdel()*
  1488.         Clear {history}, ie. delete all its entries.  See |hist-names|
  1489.         for the possible values of {history}.
  1490.  
  1491.         If the parameter {item} is given as String, this is seen
  1492.         as regular expression.  All entries matching that expression
  1493.         will be removed from the history (if there are any).
  1494.         Upper/lowercase must match, unless "\c" is used |/\c|"
  1495.         If {item} is a Number, it will be interpreted as index, see
  1496.         |:history-indexing|.  The respective entry will be removed
  1497.         if it exists.
  1498.  
  1499.         The result is a Number: 1 for a successful operation,
  1500.         otherwise 0 is returned.
  1501.  
  1502.         Examples:
  1503.         Clear expression register history: >
  1504.             :call histdel("expr")
  1505. <
  1506.         Remove all entries starting with "*" from the search history: >
  1507.             :call histdel("/", '^\*')
  1508. <
  1509.         The following three are equivalent: >
  1510.             :call histdel("search", histnr("search"))
  1511.             :call histdel("search", -1)
  1512.             :call histdel("search", '^'.histget("search", -1).'$')
  1513. <
  1514.         To delete the last search pattern and use the last-but-one for
  1515.         the "n" command and 'hlsearch': >
  1516.             :call histdel("search", -1)
  1517.             :let @/ = histget("search", -1)
  1518.  
  1519. histget({history} [, {index}])                *histget()*
  1520.         The result is a String, the entry with Number {index} from
  1521.         {history}.  See |hist-names| for the possible values of
  1522.         {history}, and |:history-indexing| for {index}.  If there is
  1523.         no such entry, an empty String is returned.  When {index} is
  1524.         omitted, the most recent item from the history is used.
  1525.  
  1526.         Examples:
  1527.         Redo the second last search from history. >
  1528.             :execute '/' . histget("search", -2)
  1529.  
  1530. <        Define an Ex command ":H {num}" that supports re-execution of
  1531.         the {num}th entry from the output of |:history|. >
  1532.             :command -nargs=1 H execute histget("cmd", 0+<args>)
  1533. <
  1534. histnr({history})                    *histnr()*
  1535.         The result is the Number of the current entry in {history}.
  1536.         See |hist-names| for the possible values of {history}.
  1537.         If an error occurred, -1 is returned.
  1538.  
  1539.         Example: >
  1540.             :let inp_index = histnr("expr")
  1541. <
  1542. hlexists({name})                    *hlexists()*
  1543.         The result is a Number, which is non-zero if a highlight group
  1544.         called {name} exists.  This is when the group has been
  1545.         defined in some way.  Not necessarily when highlighting has
  1546.         been defined for it, it may also have been used for a syntax
  1547.         item.
  1548.                             *highlight_exists()*
  1549.         Obsolete name: highlight_exists().
  1550.  
  1551.                             *hlID()*
  1552. hlID({name})    The result is a Number, which is the ID of the highlight group
  1553.         with name {name}.  When the highlight group doesn't exist,
  1554.         zero is returned.
  1555.         This can be used to retrieve information about the highlight
  1556.         group.  For example, to get the background color of the
  1557.         "Comment" group: >
  1558.     :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
  1559. <                            *highlightID()*
  1560.         Obsolete name: highlightID().
  1561.  
  1562. hostname()                        *hostname()*
  1563.         The result is a String, which is the name of the machine on
  1564.         which Vim is currently running. Machine names greater than
  1565.         256 characters long are truncated.
  1566.  
  1567. iconv({expr}, {from}, {to})                *iconv()*
  1568.         The result is a String, which is the text {expr} converted
  1569.         from encoding {from} to encoding {to}.
  1570.         When the conversion fails an empty string is returned.
  1571.         The encoding names are whatever the iconv() library function
  1572.         can accept, see ":!man 3 iconv".
  1573.         Most conversions require Vim to be compiled with the |+iconv|
  1574.         feature.  Otherwise only UTF-8 to latin1 conversion and back
  1575.         can be done.
  1576.         This can be used to display messages with special characters,
  1577.         no matter what 'encoding' is set to.  Write the message in
  1578.         UTF-8 and use: >
  1579.             echo iconv(utf8_str, "utf-8", &enc)
  1580. <        Note that Vim uses UTF-8 for all Unicode encodings, conversion
  1581.         from/to UCS-2 is automatically changed to use UTF-8.  You
  1582.         cannot use UCS-2 in a string anyway, because of the NUL bytes.
  1583.         {only available when compiled with the +multi_byte feature}
  1584.  
  1585.                             *indent()*
  1586. indent({lnum})    The result is a Number, which is indent of line {lnum} in the
  1587.         current buffer.  The indent is counted in spaces, the value
  1588.         of 'tabstop' is relevant.  {lnum} is used just like in
  1589.         |getline()|.
  1590.         When {lnum} is invalid -1 is returned.
  1591.  
  1592. input({prompt} [, {text}])                *input()*
  1593.         The result is a String, which is whatever the user typed on
  1594.         the command-line.  The parameter is either a prompt string, or
  1595.         a blank string (for no prompt).  A '\n' can be used in the
  1596.         prompt to start a new line.  The highlighting set with
  1597.         |:echohl| is used for the prompt.  The input is entered just
  1598.         like a command-line, with the same editing commands and
  1599.         mappings.  There is a separate history for lines typed for
  1600.         input().
  1601.         If the optional {text} is present, this is used for the
  1602.         default reply, as if the user typed this.
  1603.         NOTE: This must not be used in a startup file, for the
  1604.         versions that only run in GUI mode (e.g., the Win32 GUI).
  1605.  
  1606.         Example: >
  1607.             :if input("Coffee or beer? ") == "beer"
  1608.             :  echo "Cheers!"
  1609.             :endif
  1610. <        Example with default text: >
  1611.             :let color = input("Color? ", "white")
  1612.  
  1613. inputdialog({prompt} [, {text})                *inputdialog()*
  1614.         Like input(), but when the GUI is running and text dialogs are
  1615.         supported, a dialog window pops up to input the text.
  1616.         Example: >
  1617.             :let n = inputdialog("value for shiftwidth", &sw)
  1618.             :if n != ""
  1619.             :  let &sw = n
  1620.             :endif
  1621. <        Hitting <Enter> works like pressing the OK button.  Hitting
  1622.         <Esc> works like pressing the Cancel button.
  1623.  
  1624. inputsecret({prompt} [, {text}])            *inputsecret()*
  1625.         This function acts much like the |input()| function with but
  1626.         two exceptions:
  1627.         a) the user's response will be displayed as a sequence of
  1628.         asterisks ("*") thereby keeping the entry secret, and
  1629.         b) the user's response will not be recorded on the input
  1630.         |history| stack.
  1631.         The result is a String, which is whatever the user actually
  1632.         typed on the command-line in response to the issued prompt.
  1633.  
  1634. isdirectory({directory})                *isdirectory()*
  1635.         The result is a Number, which is non-zero when a directory
  1636.         with the name {directory} exists.  If {directory} doesn't
  1637.         exist, or isn't a directory, the result is FALSE.  {directory}
  1638.         is any expression, which is used as a String.
  1639.  
  1640.                         *libcall()* *E364* *E368*
  1641. libcall({libname}, {funcname}, {argument})
  1642.         Call function {funcname} in the run-time library {libname}
  1643.         with single argument {argument}.
  1644.         This is useful to call functions in a library that you
  1645.         especially made to be used with Vim.  Since only one argument
  1646.         is possible, calling standard library functions is rather
  1647.         limited.
  1648.         The result is the String returned by the function.  If the
  1649.         function returns NULL, this will appear as an empty string ""
  1650.         to Vim.
  1651.         If the function returns a number, use libcallnr()!
  1652.         If {argument} is a number, it is passed to the function as an
  1653.         int; if {param} is a string, it is passed as a null-terminated
  1654.         string.
  1655.  
  1656.         libcall() allows you to write your own 'plug-in' extensions to
  1657.         Vim without having to recompile the program.  It is NOT a
  1658.         means to call system functions!  If you try to do so Vim will
  1659.         very probably crash.
  1660.  
  1661.         For Win32, the functions you write must be placed in a DLL
  1662.         and use the normal C calling convention (NOT Pascal which is
  1663.         used in Windows System DLLs).  The function must take exactly
  1664.         one parameter, either a character pointer or a long integer,
  1665.         and must return a character pointer or NULL.  The character
  1666.         pointer returned must point to memory that will remain valid
  1667.         after the function has returned (e.g. in static data in the
  1668.         DLL).  If it points to allocated memory, that memory will
  1669.         leak away.  Using a static buffer in the function should work,
  1670.         it's then freed when the DLL is unloaded.
  1671.  
  1672.         WARNING: If the function returns a non-valid pointer, Vim may
  1673.         crash!  This also happens if the function returns a number,
  1674.         because Vim thinks it's a pointer.
  1675.         For Win32 systems, {libname} should be the filename of the DLL
  1676.         without the ".DLL" suffix.  A full path is only required if
  1677.         the DLL is not in the usual places.
  1678.         For Unix: When compiling your own plugins, remember that the
  1679.         object code must be compiled as position-independant ('PIC').
  1680.         {only in Win32 on some Unix versions, when the |+libcall|
  1681.         feature is present}
  1682.         Examples: >
  1683.             :echo libcall("libc.so", "getenv", "HOME")
  1684.             :echo libcallnr("/usr/lib/libc.so", "getpid", "")
  1685. <
  1686.                             *libcallnr()*
  1687. libcallnr({libname}, {funcname}, {argument})
  1688.         Just like libcall(), but used for a function that returns an
  1689.         int instead of a string.
  1690.         {only in Win32 on some Unix versions, when the |+libcall|
  1691.         feature is present}
  1692.         Example (not very useful...): >
  1693.             :call libcallnr("libc.so", "printf", "Hello World!\n")
  1694.             :call libcallnr("libc.so", "sleep", 10)
  1695. <
  1696.                             *line()*
  1697. line({expr})    The result is a Number, which is the line number of the file
  1698.         position given with {expr}.  The accepted positions are:
  1699.             .        the cursor position
  1700.             $        the last line in the current buffer
  1701.             'x        position of mark x (if the mark is not set, 0 is
  1702.                 returned)
  1703.         Note that only marks in the current file can be used.
  1704.         Examples: >
  1705.             line(".")        line number of the cursor
  1706.             line("'t")        line number of mark t
  1707.             line("'" . marker)    line number of mark marker
  1708. <                            *last-position-jump*
  1709.         This autocommand jumps to the last known position in a file
  1710.         just after opening it, if the '" mark is set: >
  1711.     :au BufReadPost * if line("'\"") | exe "normal '\"" | endif
  1712. <
  1713. line2byte({lnum})                    *line2byte()*
  1714.         Return the byte count from the start of the buffer for line
  1715.         {lnum}.  This includes the end-of-line character, depending on
  1716.         the 'fileformat' option for the current buffer.  The first
  1717.         line returns 1.
  1718.         This can also be used to get the byte count for the line just
  1719.         below the last line: >
  1720.             line2byte(line("$") + 1)
  1721. <        This is the file size plus one.
  1722.         When {lnum} is invalid, or the |+byte_offset| feature has been
  1723.         disabled at compile time, -1 is returned.
  1724.         Also see |byte2line()|, |go| and |:goto|.
  1725.  
  1726. lispindent({lnum})                    *lispindent()*
  1727.         Get the amount of indent for line {lnum} according the lisp
  1728.         indenting rules, as with 'lisp'.
  1729.         The indent is counted in spaces, the value of 'tabstop' is
  1730.         relevant.  {lnum} is used just like in |getline()|.
  1731.         When {lnum} is invalid or Vim was not compiled the
  1732.         |+lispindent| feature, -1 is returned.
  1733.  
  1734. localtime()                        *localtime()*
  1735.         Return the current time, measured as seconds since 1st Jan
  1736.         1970.  See also |strftime()| and |getftime()|.
  1737.  
  1738. maparg({name}[, {mode}])                *maparg()*
  1739.         Return the rhs of mapping {name} in mode {mode}.  When there
  1740.         is no mapping for {name}, an empty String is returned.
  1741.         These characters can be used for {mode}:
  1742.             "n"    Normal
  1743.             "v"    Visual
  1744.             "o"    Operator-pending
  1745.             "i"    Insert
  1746.             "c"    Cmd-line
  1747.             ""    Normal, Visual and Operator-pending
  1748.         When {mode} is omitted, the modes from "" are used.
  1749.         The {name} can have special key names, like in the ":map"
  1750.         command.  The returned String has special characters
  1751.         translated like in the output of the ":map" command listing.
  1752.         The mappings local to the current buffer are checked first,
  1753.         then the global mappings.
  1754.  
  1755. mapcheck({name}[, {mode}])                *mapcheck()*
  1756.         Check if there is a mapping that matches with {name} in mode
  1757.         {mode}.  See |maparg()| for {mode} and special names in
  1758.         {name}.
  1759.         A match happens with a mapping that starts with {name} and
  1760.         with a mapping which is equal to the start of {name}.
  1761.  
  1762.             matches mapping "a"     "ab"    "abc" ~
  1763.            mapcheck("a")    yes    yes     yes
  1764.            mapcheck("abc")    yes    yes     yes
  1765.            mapcheck("ax")    yes    no     no
  1766.            mapcheck("b")    no    no     no
  1767.  
  1768.         The difference with maparg() is that mapcheck() finds a
  1769.         mapping that matches with {name}, while maparg() only finds a
  1770.         mapping for {name} exactly.
  1771.         When there is no mapping that starts with {name}, an empty
  1772.         String is returned.  If there is one, the rhs of that mapping
  1773.         is returned.  If there are several mappings that start with
  1774.         {name}, the rhs of one of them is returned.
  1775.         The mappings local to the current buffer are checked first,
  1776.         then the global mappings.
  1777.         This function can be used to check if a mapping can be added
  1778.         without being ambiguous.  Example: >
  1779.     :if mapcheck("_vv") == ""
  1780.     :   map _vv :set guifont=7x13<CR>
  1781.     :endif
  1782. <        This avoids adding the "_vv" mapping when there already is a
  1783.         mapping for "_v" or for "_vvv".
  1784.  
  1785. match({expr}, {pat}[, {start}])                *match()*
  1786.         The result is a Number, which gives the index in {expr} where
  1787.         {pat} matches.  A match at the first character returns zero.
  1788.         If there is no match -1 is returned.  Example: >
  1789.             :echo match("testing", "ing")
  1790. <        results in "4".
  1791.         See |string-match| for how {pat} is used.
  1792.         If {start} is given, the search starts from character {start}.
  1793.         The result, however, is still the index counted from the
  1794.         first character. Example: >
  1795.             :echo match("testing", "ing", 2)
  1796. <        result is again "4". >
  1797.             :echo match("testing", "ing", 4)
  1798. <        result is again "4". >
  1799.             :echo match("testing", "t", 2)
  1800. <        result is "3".
  1801.         If {start} < 0, it will be set to 0.
  1802.         If {start} > strlen({expr}) -1 is returned.
  1803.         See |pattern| for the patterns that are accepted.
  1804.         The 'ignorecase' option is used to set the ignore-caseness of
  1805.         the pattern.  'smartcase' is NOT used.  The matching is always
  1806.         done like 'magic' is set and 'cpoptions' is empty.
  1807.  
  1808. matchend({expr}, {pat}[, {start}])            *matchend()*
  1809.         Same as match(), but return the index of first character after
  1810.         the match.  Example: >
  1811.             :echo matchend("testing", "ing")
  1812. <        results in "7".
  1813.         The {start}, if given, has the same meaning as for match(). >
  1814.             :echo matchend("testing", "ing", 2)
  1815. <        results in "7". >
  1816.             :echo matchend("testing", "ing", 5)
  1817. <        result is "-1".
  1818.  
  1819. matchstr({expr}, {pat}[, {start}])            *matchstr()*
  1820.         Same as match(), but return the matched string.  Example: >
  1821.             :echo matchstr("testing", "ing")
  1822. <        results in "ing".
  1823.         When there is no match "" is returned.
  1824.         The {start}, if given, has the same meaning as for match(). >
  1825.             :echo matchstr("testing", "ing", 2)
  1826. <        results in "ing". >
  1827.             :echo matchstr("testing", "ing", 5)
  1828. <        result is "".
  1829.  
  1830.                             *mode()*
  1831. mode()        Return a string that indicates the current mode:
  1832.             n    Normal
  1833.             v    Visual by character
  1834.             V    Visual by line
  1835.             CTRL-V    Visual blockwise
  1836.             s    Select by character
  1837.             S    Select by line
  1838.             CTRL-S    Select blockwise
  1839.             i    Insert
  1840.             R    Replace
  1841.             c    Command-line
  1842.             r    Hit-enter prompt
  1843.         This is useful in the 'statusline' option.  In most other
  1844.         places it always returns "c" or "n".
  1845.  
  1846. nextnonblank({lnum})                    *nextnonblank()*
  1847.         Return the line number of the first line at or below {lnum}
  1848.         that is not blank.  Example: >
  1849.             if getline(nextnonblank(1)) =~ "Java"
  1850. <        When {lnum} is invalid or there is no non-blank line at or
  1851.         below it, zero is returned.
  1852.         See also |prevnonblank()|.
  1853.  
  1854. nr2char({expr})                        *nr2char()*
  1855.         Return a string with a single character, which has the ASCII
  1856.         value {expr}.  Examples: >
  1857.             nr2char(64)        returns "@"
  1858.             nr2char(32)        returns " "
  1859. <
  1860. prevnonblank({lnum})                    *prevnonblank()*
  1861.         Return the line number of the first line at or above {lnum}
  1862.         that is not blank.  Example: >
  1863.             let ind = indent(prevnonblank(v:lnum - 1))
  1864. <        When {lnum} is invalid or there is no non-blank line at or
  1865.         above it, zero is returned.
  1866.  
  1867.                             *remote_expr()*
  1868. remote_expr({server}, {string} [, {idvar}])
  1869.         Send the {string} to {server}.  The string is sent as an
  1870.         expression and the result is returned after evaluation.
  1871.         If {idvar} is present, it is taken as the name of a
  1872.         variable and a {serverid} for later use with
  1873.         remote_read() is stored there.
  1874.         See also |clientserver| |RemoteReply|.
  1875.         {only available when compiled with the |+clientserver| feature}
  1876.         Note: Any errors will be reported in the server and may mess
  1877.         up the display.
  1878.         Examples: >
  1879.             :echo remote_expr("gvim", "2+2")
  1880.             :echo remote_expr("gvim-001", "b:current_syntax")
  1881. <
  1882.  
  1883. remote_foreground({server})                *remote_foreground()*
  1884.         Move the Vim server with the name {server} to the foreground.
  1885.         This works like: >
  1886.             remote_expr({server}, "foreground()")
  1887. <        Except that on Win32 systems the client does the work, to work
  1888.         around the problem that the OS doesn't always allow the server
  1889.         to bring itself to the foreground.
  1890.         {only in the Win32, Athena, Motif and GTK GUI versions and the
  1891.         Win32 console version}
  1892.  
  1893.  
  1894. remote_peek({serverid} [, {retvar}])        *remote_peek()*
  1895.         Returns a positive number if there are available strings
  1896.         from {serverid}.  Copies any reply string into the variable
  1897.         {retvar} if specified.  {retvar} must be a string with the
  1898.         name of a variable.
  1899.         Returns zero if none are available.
  1900.         See also |clientserver|.
  1901.         {only available when compiled with the |+clientserver| feature}
  1902.         Examples: >
  1903.             :let repl = ""
  1904.             :echo "PEEK: ".remote_peek(id, "repl").": ".repl
  1905.  
  1906. remote_read({serverid})                *remote_read()*
  1907.         Return the oldest available reply from {serverid} and consume
  1908.         it.  It blocks until a reply is available.
  1909.         See also |clientserver|.
  1910.         {only available when compiled with the |+clientserver| feature}
  1911.         Examples: >
  1912.             :echo remote_read(id)
  1913. <
  1914.                             *remote_send()* *E241*
  1915. remote_send({server}, {string} [, {idvar}])
  1916.         Send the {string} to {server}.  The string is sent as
  1917.         input keys and the function returns immediately.
  1918.         If {idvar} is present, it is taken as the name of a
  1919.         variable and a {serverid} for later use with
  1920.         remote_read() is stored there.
  1921.         See also |clientserver| |RemoteReply|.
  1922.         {only available when compiled with the |+clientserver| feature}
  1923.         Note: Any errors will be reported in the server and may mess
  1924.         up the display.
  1925.         Examples: >
  1926.         :echo remote_send("gvim", ":DropAndReply ".file, "serverid").
  1927.          \ remote_read(serverid)
  1928.  
  1929.         :autocmd NONE RemoteReply *
  1930.          \ echo remote_read(expand("<amatch>"))
  1931.         :echo remote_send("gvim", ":sleep 10 | echo ".
  1932.          \ 'server2client(expand("<client>"), "HELLO")<CR>')
  1933.  
  1934.  
  1935. rename({from}, {to})                    *rename()*
  1936.         Rename the file by the name {from} to the name {to}.  This
  1937.         should also work to move files across file systems.  The
  1938.         result is a Number, which is 0 if the file was renamed
  1939.         successfully, and non-zero when the renaming failed.
  1940.  
  1941. resolve({filename})                    *resolve()*
  1942.         On MS-Windows, when {filename} is a shortcut (a .lnk file),
  1943.         returns the path the shortcut points to.
  1944.         On Unix, when {filename} is a symbolic link, returns the path
  1945.         the symlink points to.  This only happens once, the returned
  1946.         path could be a symlink again.
  1947.         Otherwise {filename} is returned.
  1948.  
  1949. search({pattern} [, {flags}])                *search()*
  1950.         Search for regexp pattern {pattern}.  The search starts at the
  1951.         cursor position.
  1952.         {flags} is a String, which can contain these character flags:
  1953.         'b'    search backward instead of forward
  1954.         'w'    wrap around the end of the file
  1955.         'W'    don't wrap around the end of the file
  1956.         If neither 'w' or 'W' is given, the 'wrapscan' option applies.
  1957.  
  1958.         When a match has been found its line number is returned, and
  1959.         the cursor will be positioned at the match.  If there is no
  1960.         match a 0 is returned and the cursor doesn't move.  No error
  1961.         message is given.
  1962.  
  1963.         Example (goes over all files in the argument list): >
  1964.             :let n = 1
  1965.             :while n <= argc()        " loop over all files in arglist
  1966.             :  exe "argument " . n
  1967.             :  " start at the last char in the file and wrap for the
  1968.             :  " first search to find match at start of file
  1969.             :  normal G$
  1970.             :  let flags = "w"
  1971.             :  while search("foo", flags) > 0
  1972.             :    s/foo/bar/g
  1973.             :     let flags = "W"
  1974.             :  endwhile
  1975.             :  update            " write the file if modified
  1976.             :  let n = n + 1
  1977.             :endwhile
  1978. <
  1979.                             *searchpair()*
  1980. searchpair({start}, {middle}, {end} [, {flags} [, {skip}]])
  1981.         Search for the match of a nested start-end pair.  This can be
  1982.         used to find the "endif" that matches an "if", while other
  1983.         if/endif pairs in between are ignored.
  1984.         The search starts at the cursor.  If a match is found, the
  1985.         cursor is positioned at it and the line number is returned.
  1986.         If no match is found 0 or -1 is returned and the cursor
  1987.         doesn't move.  No error message is given.
  1988.  
  1989.         {start}, {middle} and {end} are patterns, see |pattern|.  They
  1990.         must not contain \( \) pairs.  Use of \%( \) is allowed.  When
  1991.         {middle} is not empty, it is found when searching from either
  1992.         direction, but only when not in a nested start-end pair.  A
  1993.         typical use is: >
  1994.             searchpair("if", "else", "endif")
  1995. <        By leaving {middle} empty the "else" is skipped.
  1996.  
  1997.         {flags} are used like with |search()|.  Additionally:
  1998.         'n'    do Not move the cursor
  1999.         'r'    repeat until no more matches found; will find the
  2000.             outer pair
  2001.         'm'    return number of matches instead of line number with
  2002.             the match; will only be > 1 when 'r' is used.
  2003.  
  2004.         When a match for {start}, {middle} or {end} is found, the
  2005.         {skip} expression is evaluated with the cursor positioned on
  2006.         the start of the match.  It should return non-zero if this
  2007.         match is to be skipped.  E.g., because it is inside a comment
  2008.         or a string.
  2009.         When {skip} is omitted or empty, every match is accepted.
  2010.         When evaluating {skip} causes an error the search is aborted
  2011.         and -1 returned.
  2012.  
  2013.         The value of 'ignorecase' is used.  'magic' is ignored, the
  2014.         patterns are used like it's on.
  2015.  
  2016.         The search starts exactly at the cursor.  A match with
  2017.         {start}, {middle} or {end} at the next character, in the
  2018.         direction of searching, is the first one found.  Example: >
  2019.             if 1
  2020.               if 2
  2021.               endif 2
  2022.             endif 1
  2023. <        When starting at the "if 2", with the cursor on the "i", and
  2024.         searching forwards, the "endif 2" is found.  When starting on
  2025.         the character just before the "if 2", the "endif 1" will be
  2026.         found.  That's because the "if 2" will be found first, and
  2027.         then this is considered to be a nested if/endif from "if 2" to
  2028.         "endif 2".
  2029.  
  2030.         Example, to find the "endif" command in a Vim script: >
  2031.  
  2032.     :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
  2033.             \ 'getline(".") =~ "^\\s*\""')
  2034.  
  2035. <        The cursor must be at or after the "if" for which a match is
  2036.         to be found.  Note that single-quote strings are used to avoid
  2037.         having to double the backslashes.  The skip expression only
  2038.         catches comments at the start of a line, not after a command.
  2039.         Also, a word "en" or "if" halfway a line is considered a
  2040.         match.
  2041.         Another example, to search for the matching "{" of a "}": >
  2042.  
  2043.     :echo searchpair('{', '', '}', 'bW')
  2044.  
  2045. <        This works when the cursor is at or before the "}" for which a
  2046.         match is to be found.  To reject matches that syntax
  2047.         highlighting recognized as strings: >
  2048.  
  2049.     :echo searchpair('{', '', '}', 'bW',
  2050.          \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
  2051. <
  2052. server2client( {clientid}, {string})            *server2client()*
  2053.         Send a reply string to {clientid}. The most recent {clientid}
  2054.         that sent a string can be retrieved with expand("<client>").
  2055.         {only available when compiled with the |+clientserver| feature}
  2056.         Note:
  2057.         This id has to be stored before the next command can be
  2058.         received. Ie. before returning from the received command and
  2059.         before calling any commands that waits for input.
  2060.         See also |clientserver|.
  2061.         Examples: >
  2062.         :echo server2client(expand("<client>"), "HELLO")
  2063. <
  2064. serverlist()                    *serverlist()* *E240*
  2065.         Return a list of available server names. One per line.
  2066.         See also |clientserver|.
  2067.         {only available when compiled with the |+clientserver| feature}
  2068.         Examples: >
  2069.         :echo serverlist()
  2070. <
  2071. setbufvar({expr}, {varname}, {val})            *setbufvar()*
  2072.         Set option or local variable {varname} in buffer {expr} to
  2073.         {val}.
  2074.         This also works for a global or local window option, but it
  2075.         doesn't work for a global or local window variable.
  2076.         For a local window option the global value is unchanged.
  2077.         For the use of {expr}, see |bufname()| above.
  2078.         Note that the variable name without "b:" must be used.
  2079.         Examples: >
  2080.             :call setbufvar(1, "&mod", 1)
  2081.             :call setbufvar("todo", "myvar", "foobar")
  2082. <
  2083. setline({lnum}, {line})                    *setline()*
  2084.         Set line {lnum} of the current buffer to {line}.  If this
  2085.         succeeds, 0 is returned.  If this fails (most likely because
  2086.         {lnum} is invalid) 1 is returned.  Example: >
  2087.             :call setline(5, strftime("%c"))
  2088. <        Note: The '[ and '] marks are not set.
  2089.  
  2090. setwinvar({nr}, {varname}, {val})            *setwinvar()*
  2091.         Set option or local variable {varname} in window {nr} to
  2092.         {val}.
  2093.         This also works for a global or local buffer option, but it
  2094.         doesn't work for a global or local buffer variable.
  2095.         For a local buffer option the global value is unchanged.
  2096.         Note that the variable name without "w:" must be used.
  2097.         Examples: >
  2098.             :call setwinvar(1, "&list", 0)
  2099.             :call setwinvar(2, "myvar", "foobar")
  2100. <
  2101. strftime({format} [, {time}])                *strftime()*
  2102.         The result is a String, which is a formatted date and time, as
  2103.         specified by the {format} string.  The given {time} is used,
  2104.         or the current time if no time is given.  The accepted
  2105.         {format} depends on your system, thus this is not portable!
  2106.         See the manual page of the C function strftime() for the
  2107.         format.  The maximum length of the result is 80 characters.
  2108.         See also |localtime()| and |getftime()|.
  2109.         The language can be changed with the |:language| command.
  2110.         Examples: >
  2111.           :echo strftime("%c")           Sun Apr 27 11:49:23 1997
  2112.           :echo strftime("%Y %b %d %X")       1997 Apr 27 11:53:25
  2113.           :echo strftime("%y%m%d %T")       970427 11:53:55
  2114.           :echo strftime("%H:%M")       11:55
  2115.           :echo strftime("%c", getftime("file.c"))
  2116.                            Show mod time of file.c.
  2117. <
  2118. stridx({haystack}, {needle})                *stridx()*
  2119.         The result is a Number, which gives the index in {haystack} of
  2120.         the first occurrence of the String {needle} in the String
  2121.         {haystack}. The search is done case-sensitive. For advanced
  2122.         searches use |match()|.
  2123.         If the {needle} does not occur in {haystack} it returns -1.
  2124.         See also |strridx()|. Examples: >
  2125.           :echo stridx("An Example", "Example")         3
  2126.           :echo stridx("Starting point", "Start")    0
  2127.           :echo stridx("Starting point", "start")   -1
  2128. <
  2129.                             *strlen()*
  2130. strlen({expr})    The result is a Number, which is the length of the String
  2131.         {expr}.
  2132.  
  2133. strpart({src}, {start}[, {len}])            *strpart()*
  2134.         The result is a String, which is part of {src},
  2135.         starting from character {start}, with the length {len}.
  2136.         When non-existing characters are included, this doesn't result
  2137.         in an error, the characters are simply omitted.
  2138.         If {len} is missing, the copy continues from {start} till
  2139.         the end of the {src}. >
  2140.             strpart("abcdefg", 3, 2)    == "de"
  2141.             strpart("abcdefg", -2, 4)   == "ab"
  2142.             strpart("abcdefg", 5, 4)    == "fg"
  2143.             strpart("abcdefg", 3)       == "defg"
  2144. <        Note: To get the first character, {start} must be 0.  For
  2145.         example, to get three characters under and after the cursor: >
  2146.             strpart(getline(line(".")), col(".") - 1, 3)
  2147. <
  2148. strridx({haystack}, {needle})                *strridx()*
  2149.         The result is a Number, which gives the index in {haystack} of
  2150.         the last occurrence of the String {needle} in the String
  2151.         {haystack}. The search is done case-sensitive. For advanced
  2152.         searches use |match()|.
  2153.         If the {needle} does not occur in {haystack} it returns -1.
  2154.         See also |stridx()|. Examples: >
  2155.           :echo strridx("an angry armadillo", "an")         3
  2156. <
  2157. strtrans({expr})                    *strtrans()*
  2158.         The result is a String, which is {expr} with all unprintable
  2159.         characters translated into printable characters |'isprint'|.
  2160.         Like they are shown in a window.  Example: >
  2161.             echo strtrans(@a)
  2162. <        This displays a newline in register a as "^@" instead of
  2163.         starting a new line.
  2164.  
  2165. submatch({nr})                        *submatch()*
  2166.         Only for an expression in a |:substitute| command.  Returns
  2167.         the {nr}'th submatch of the matched text  When {nr} is 0
  2168.         the whole matched text is returned.
  2169.         Example: >
  2170.             :s/\d\+/\=submatch(0) + 1/
  2171. <        This finds the first number in the line and adds one to it.
  2172.  
  2173. substitute({expr}, {pat}, {sub}, {flags})        *substitute()*
  2174.         The result is a String, which is a copy of {expr}, in which
  2175.         the first match of {pat} is replaced with {sub}.  This works
  2176.         like the ":substitute" command (without any flags).  But the
  2177.         matching with {pat} is always done like the 'magic' option is
  2178.         set and 'cpoptions' is empty (to make scripts portable).
  2179.         See |string-match| for how {pat} is used.
  2180.         And a "~" in {sub} is not replaced with the previous {sub}.
  2181.         Note that some codes in {sub} have a special meaning
  2182.         |sub-replace-special|.  For example, to replace something with
  2183.         a literal "\n", use "\\\\n" or '\\n'.
  2184.         When {pat} does not match in {expr}, {expr} is returned
  2185.         unmodified.
  2186.         When {flags} is "g", all matches of {pat} in {expr} are
  2187.         replaced.  Otherwise {flags} should be "".
  2188.         Example: >
  2189.             :let &path = substitute(&path, ",\\=[^,]*$", "", "")
  2190. <        This removes the last component of the 'path' option. >
  2191.             :echo substitute("testing", ".*", "\\U\\0", "")
  2192. <        results in "TESTING".
  2193.  
  2194. synID({line}, {col}, {trans})                *synID()*
  2195.         The result is a Number, which is the syntax ID at the position
  2196.         {line} and {col} in the current window.
  2197.         The syntax ID can be used with |synIDattr()| and
  2198.         |synIDtrans()| to obtain syntax information about text.
  2199.         {col} is 1 for the leftmost column, {line} is 1 for the first
  2200.         line.
  2201.         When {trans} is non-zero, transparent items are reduced to the
  2202.         item that they reveal.  This is useful when wanting to know
  2203.         the effective color.  When {trans} is zero, the transparent
  2204.         item is returned.  This is useful when wanting to know which
  2205.         syntax item is effective (e.g. inside parens).
  2206.         Warning: This function can be very slow.  Best speed is
  2207.         obtained by going through the file in forward direction.
  2208.  
  2209.         Example (echos the name of the syntax item under the cursor): >
  2210.             :echo synIDattr(synID(line("."), col("."), 1), "name")
  2211. <
  2212. synIDattr({synID}, {what} [, {mode}])            *synIDattr()*
  2213.         The result is a String, which is the {what} attribute of
  2214.         syntax ID {synID}.  This can be used to obtain information
  2215.         about a syntax item.
  2216.         {mode} can be "gui", "cterm" or "term", to get the attributes
  2217.         for that mode.  When {mode} is omitted, or an invalid value is
  2218.         used, the attributes for the currently active highlighting are
  2219.         used (GUI, cterm or term).
  2220.         Use synIDtrans() to follow linked highlight groups.
  2221.         {what}        result
  2222.         "name"        the name of the syntax item
  2223.         "fg"        foreground color (GUI: color name, cterm:
  2224.                 color number as a string, term: empty string)
  2225.         "bg"        background color (like "fg")
  2226.         "fg#"        like "fg", but name in "#RRGGBB" form
  2227.         "bg#"        like "bg", but name in "#RRGGBB" form
  2228.         "bold"        "1" if bold
  2229.         "italic"    "1" if italic
  2230.         "reverse"    "1" if reverse
  2231.         "inverse"    "1" if inverse (= reverse)
  2232.         "underline"    "1" if underlined
  2233.  
  2234.         When the GUI is not running or the cterm mode is asked for,
  2235.         "fg#" is equal to "fg" and "bg#" is equal to "bg".
  2236.  
  2237.         Example (echos the color of the syntax item under the cursor): >
  2238.     :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
  2239. <
  2240. synIDtrans({synID})                    *synIDtrans()*
  2241.         The result is a Number, which is the translated syntax ID of
  2242.         {synID}.  This is the syntax group ID of what is being used to
  2243.         highlight the character.  Highlight links given with
  2244.         ":highlight link" are followed.
  2245.  
  2246.                             *system()*
  2247. system({expr})    Get the output of the shell command {expr}.  Note: newlines
  2248.         in {expr} may cause the command to fail.  This is not to be
  2249.         used for interactive commands.
  2250.         The result is a String.  To make the result more
  2251.         system-independent, the shell output is filtered to replace
  2252.         <CR> with <NL> for Macintosh, and <CR><NL> with <NL> for
  2253.         DOS-like systems.
  2254.         'shellredir' is used to capture the output of the command.
  2255.         Depending on 'shell', you might be able to capture stdout with
  2256.         ">" and stdout plus stderr with ">&" (csh) or use "2>" to
  2257.         capture stderr (sh).
  2258.         The resulting error code can be found in |v:shell_error|.
  2259.         This function will fail in |restricted-mode|.
  2260.  
  2261. tempname()                    *tempname()* *temp-file-name*
  2262.         The result is a String, which is the name of a file that
  2263.         doesn't exist.  It can be used for a temporary file.  The name
  2264.         is different for at least 26 consecutive calls.  Example: >
  2265.             :let tmpfile = tempname()
  2266.             :exe "redir > " . tmpfile
  2267. <        For Unix, the file will be in a private directory (only
  2268.         accessible by the current user) to avoid security problems
  2269.         (e.g., a symlink attack or other people reading your file).
  2270.         When Vim exits the directory and all files in it are deleted.
  2271.  
  2272. tolower({expr})                        *tolower()*
  2273.         The result is a copy of the String given, with all uppercase
  2274.         characters turned into lowercase (just like applying |gu| to
  2275.         the string).
  2276.  
  2277. toupper({expr})                        *toupper()*
  2278.         The result is a copy of the String given, with all lowercase
  2279.         characters turned into uppercase (just like applying |gU| to
  2280.         the string).
  2281.  
  2282. type({expr})                        *type()*
  2283.         The result is a Number:
  2284.             0 if {expr} has the type Number
  2285.             1 if {expr} has the type String
  2286.  
  2287. virtcol({expr})                        *virtcol()*
  2288.         The result is a Number, which is the screen column of the file
  2289.         position given with {expr}.  That is, the last screen position
  2290.         occupied by the character at that position, when the screen
  2291.         would be of unlimited width.  When there is a <Tab> at the
  2292.         position, the returned Number will be the column at the end of
  2293.         the <Tab>.  For example, for a <Tab> in column 1, with 'ts'
  2294.         set to 8, it returns 8;
  2295.         The accepted positions are:
  2296.             .        the cursor position
  2297.             $        the end of the cursor line (the result is the
  2298.                 number of displayed characters in the cursor line
  2299.                 plus one)
  2300.             'x        position of mark x (if the mark is not set, 0 is
  2301.                 returned)
  2302.         Note that only marks in the current file can be used.
  2303.         Examples: >
  2304.   virtcol(".")       with text "foo^Lbar", with cursor on the "^L", returns 5
  2305.   virtcol("$")       with text "foo^Lbar", returns 9
  2306.   virtcol("'t")    with text "    there", with 't at 'h', returns 6
  2307. <        The first column is 1.  0 is returned for an error.
  2308.  
  2309. visualmode()                        *visualmode()*
  2310.         The result is a String, which describes the last Visual mode
  2311.         used.  Initially it returns an empty string, but once Visual
  2312.         mode has been used, it returns "v", "V", or "<CTRL-V>" (a
  2313.         single CTRL-V character) for character-wise, line-wise, or
  2314.         block-wise Visual mode respectively.
  2315.         Example: >
  2316.             :exe "normal " . visualmode()
  2317. <        This enters the same Visual mode as before.  It is also useful
  2318.         in scripts if you wish to act differently depending on the
  2319.         Visual mode that was used.
  2320.  
  2321.                             *winbufnr()*
  2322. winbufnr({nr})    The result is a Number, which is the number of the buffer
  2323.         associated with window {nr}. When {nr} is zero, the number of
  2324.         the buffer in the current window is returned.  When window
  2325.         {nr} doesn't exist, -1 is returned.
  2326.         Example: >
  2327.   :echo "The file in the current window is " . bufname(winbufnr(0))
  2328. <
  2329.                             *wincol()*
  2330. wincol()    The result is a Number, which is the virtual column of the
  2331.         cursor in the window.  This is counting screen cells from the
  2332.         left side of the window.  The leftmost column is one.
  2333.  
  2334. winheight({nr})                        *winheight()*
  2335.         The result is a Number, which is the height of window {nr}.
  2336.         When {nr} is zero, the height of the current window is
  2337.         returned.  When window {nr} doesn't exist, -1 is returned.
  2338.         An existing window always has a height of zero or more.
  2339.         Examples: >
  2340.   :echo "The current window has " . winheight(0) . " lines."
  2341. <
  2342.                             *winline()*
  2343. winline()    The result is a Number, which is the screen line of the cursor
  2344.         in the window.  This is counting screen lines from the top of
  2345.         the window.  The first line is one.
  2346.  
  2347.                             *winnr()*
  2348. winnr()        The result is a Number, which is the number of the current
  2349.         window.  The top window has number 1.
  2350.  
  2351. winwidth({nr})                        *winwidth()*
  2352.         The result is a Number, which is the width of window {nr}.
  2353.         When {nr} is zero, the width of the current window is
  2354.         returned.  When window {nr} doesn't exist, -1 is returned.
  2355.         An existing window always has a width of zero or more.
  2356.         Examples: >
  2357.   :echo "The current window has " . winwidth(0) . " columns."
  2358.   :if winwidth(0) <= 50
  2359.   :  exe "normal 50\<C-W>|"
  2360.   :endif
  2361. <
  2362.  
  2363.                             *feature-list*
  2364. There are two types of features:
  2365. 1.  Features that are only supported when they have been enabled when Vim
  2366.     was compiled |+feature-list|.  Example: >
  2367.     :if has("cindent")
  2368. 2.  Features that are only supported when certain conditions have been met.
  2369.     Example: >
  2370.     :if has("gui_running")
  2371.  
  2372. all_builtin_terms    Compiled with all builtin terminals enabled.
  2373. amiga            Amiga version of Vim.
  2374. arp            Compiled with ARP support (Amiga).
  2375. autocmd            Compiled with autocommands support.
  2376. balloon_eval        Compiled with |balloon-eval| support.
  2377. beos            BeOS version of Vim.
  2378. browse            Compiled with |:browse| support, and browse() will
  2379.             work.
  2380. builtin_terms        Compiled with some builtin terminals.
  2381. byte_offset        Compiled with support for 'o' in 'statusline'
  2382. cindent            Compiled with 'cindent' support.
  2383. clientserver        Compiled with remote invocation support |clientserver|.
  2384. clipboard        Compiled with 'clipboard' support.
  2385. cmdline_compl        Compiled with |cmdline-completion| support.
  2386. cmdline_hist        Compiled with |cmdline-history| support.
  2387. cmdline_info        Compiled with 'showcmd' and 'ruler' support.
  2388. comments        Compiled with |'comments'| support.
  2389. cryptv            Compiled with encryption support |encryption|.
  2390. cscope            Compiled with |cscope| support.
  2391. compatible        Compiled to be very Vi compatible.
  2392. debug            Compiled with "DEBUG" defined.
  2393. dialog_con        Compiled with console dialog support.
  2394. dialog_gui        Compiled with GUI dialog support.
  2395. diff            Compiled with |vimdiff| and 'diff' support.
  2396. digraphs        Compiled with support for digraphs.
  2397. dos32            32 bits DOS (DJGPP) version of Vim.
  2398. dos16            16 bits DOS version of Vim.
  2399. ebcdic            Compiled on a machine with ebcdic character set.
  2400. emacs_tags        Compiled with support for Emacs tags.
  2401. eval            Compiled with expression evaluation support.  Always
  2402.             true, of course!
  2403. ex_extra        Compiled with extra Ex commands |+ex_extra|.
  2404. extra_search        Compiled with support for |'incsearch'| and
  2405.             |'hlsearch'|
  2406. farsi            Compiled with Farsi support |farsi|.
  2407. file_in_path        Compiled with support for |gf| and |<cfile>|
  2408. find_in_path        Compiled with support for include file searches
  2409.             |+find_in_path|.
  2410. fname_case        Case in file names matters (for Amiga, MS-DOS, and
  2411.             Windows this is not present).
  2412. folding            Compiled with |folding| support.
  2413. footer            Compiled with GUI footer support. |gui-footer|
  2414. fork            Compiled to use fork()/exec() instead of system().
  2415. gettext            Compiled with message translation |multi-lang|
  2416. gui            Compiled with GUI enabled.
  2417. gui_athena        Compiled with Athena GUI.
  2418. gui_beos        Compiled with BeOs GUI.
  2419. gui_gtk            Compiled with GTK+ GUI.
  2420. gui_mac            Compiled with Macintosh GUI.
  2421. gui_motif        Compiled with Motif GUI.
  2422. gui_photon        Compiled with Photon GUI.
  2423. gui_win32        Compiled with MS Windows Win32 GUI.
  2424. gui_win32s        idem, and Win32s system being used (Windows 3.1)
  2425. gui_running        Vim is running in the GUI, or it will start soon.
  2426. hangul_input        Compiled with Hangul input support. |hangul|
  2427. iconv            Can use iconv() for coversion.
  2428. insert_expand        Compiled with support for CTRL-X expansion commands in
  2429.             Insert mode.
  2430. jumplist        Compiled with |jumplist| support.
  2431. keymap            Compiled with 'keymap' support.
  2432. langmap            Compiled with 'langmap' support.
  2433. libcall            Compiled with |libcall()| support.
  2434. linebreak        Compiled with 'linebreak', 'breakat' and 'showbreak'
  2435.             support.
  2436. lispindent        Compiled with support for lisp indenting.
  2437. listcmds        Compiled with commands for the buffer list |:files|
  2438.             and the argument list |arglist|.
  2439. localmap        Compiled with local mappings and abbr. |:map-local|
  2440. mac            Macintosh version of Vim.
  2441. menu            Compiled with support for |:menu|.
  2442. mksession        Compiled with support for |:mksession|.
  2443. modify_fname        Compiled with file name modifiers. |filename-modifiers|
  2444. mouse            Compiled with support mouse.
  2445. mouseshape        Compiled with support for 'mouseshape'.
  2446. mouse_dec        Compiled with support for Dec terminal mouse.
  2447. mouse_gpm        Compiled with support for gpm (Linux console mouse)
  2448. mouse_netterm        Compiled with support for netterm mouse.
  2449. mouse_pterm        Compiled with support for qnx pterm mouse.
  2450. mouse_xterm        Compiled with support for xterm mouse.
  2451. multi_byte        Compiled with support for editing Korean et al.
  2452. multi_byte_ime        Compiled with support for IME input method.
  2453. multi_lang        Compiled with support for multiple languages.
  2454. ole            Compiled with OLE automation support for Win32.
  2455. os2            OS/2 version of Vim.
  2456. osfiletype        Compiled with support for osfiletypes |+osfiletype|
  2457. path_extra        Compiled with up/downwards search in 'path' and 'tags'
  2458. perl            Compiled with Perl interface.
  2459. postscript        Compiled with PostScript file printing.
  2460. printer            Compiled with |:hardcopy| support.
  2461. python            Compiled with Python interface.
  2462. qnx            QNX version of vim.
  2463. quickfix        Compiled with |quickfix| support.
  2464. rightleft        Compiled with 'rightleft' support.
  2465. ruby            Compiled with Ruby interface |ruby|.
  2466. scrollbind        Compiled with 'scrollbind' support.
  2467. showcmd            Compiled with 'showcmd' support.
  2468. signs            Compiled with |:sign| support.
  2469. smartindent        Compiled with 'smartindent' support.
  2470. sniff            Compiled with SniFF interface support.
  2471. statusline        Compiled with support for 'statusline', 'rulerformat'
  2472.             and special formats of 'titlestring' and 'iconstring'.
  2473. sun_workshop        Compiled with support for Sun |workshop|.
  2474. syntax            Compiled with syntax highlighting support.
  2475. syntax_items        There are active syntax highlighting items for the
  2476.             current buffer.
  2477. system            Compiled to use system() instead of fork()/exec().
  2478. tag_binary        Compiled with binary searching in tags files
  2479.             |tag-binary-search|.
  2480. tag_old_static        Compiled with support for old static tags
  2481.             |tag-old-static|.
  2482. tag_any_white        Compiled with support for any white characters in tags
  2483.             files |tag-any-white|.
  2484. tcl            Compiled with Tcl interface.
  2485. terminfo        Compiled with terminfo instead of termcap.
  2486. termresponse        Compiled with support for |t_RV| and |v:termresponse|.
  2487. textobjects        Compiled with support for |text-objects|.
  2488. tgetent            Compiled with tgetent support, able to use a termcap
  2489.             or terminfo file.
  2490. title            Compiled with window title support |'title'|.
  2491. toolbar            Compiled with support for |gui-toolbar|.
  2492. unix            Unix version of Vim.
  2493. user_commands        User-defined commands.
  2494. viminfo            Compiled with viminfo support.
  2495. vim_starting        True while initial source'ing takes place.
  2496. vertsplit        Compiled with vertically split windows |:vsplit|.
  2497. virtualedit        Compiled with 'virtualedit' option.
  2498. visual            Compiled with Visual mode.
  2499. visualextra        Compiled with extra Visual mode commands.
  2500.             |blockwise-operators|.
  2501. vms            VMS version of Vim.
  2502. vreplace        Compiled with |gR| and |gr| commands.
  2503. wildignore        Compiled with 'wildignore' option.
  2504. wildmenu        Compiled with 'wildmenu' option.
  2505. windows            Compiled with support for more than one window.
  2506. winaltkeys        Compiled with 'winaltkeys' option.
  2507. win16            Win16 version of Vim (MS-Windows 3.1).
  2508. win32            Win32 version of Vim (MS-Windows 95/98/ME/NT/2000/XP).
  2509. win95            Win32 version for MS-Windows 95/98/ME.
  2510. writebackup        Compiled with 'writebackup' default on.
  2511. xfontset        Compiled with X fontset support |xfontset|.
  2512. xim            Compiled with X input method support |xim|.
  2513. xterm_clipboard        Compiled with support for xterm clipboard.
  2514. xterm_save        Compiled with support for saving and restoring the
  2515.             xterm screen.
  2516. x11            Compiled with X11 support.
  2517.  
  2518.                             *string-match*
  2519. Matching a pattern in a String
  2520.  
  2521. A regexp pattern as explained at |pattern| is normally used to find a match in
  2522. the buffer lines.  When a pattern is used to find a match in a String, almost
  2523. everything works in the same way.  The difference is that a String is handled
  2524. like it is one line.  When it contains a "\n" character, this is not seen as a
  2525. line break for the pattern.  It can be matched with a "\n" in the pattern, or
  2526. with ".".  Example: >
  2527.     :let a = "aaaa\nxxxx"
  2528.     :echo matchstr(a, "..\n..")
  2529.     aa
  2530.     xx
  2531.     :echo matchstr(a, "a.x")
  2532.     a
  2533.     x
  2534.  
  2535. Don't forget that "^" will only match at the first character of the String and
  2536. "$" at the last character of the string.  They don't match after or before a
  2537. "\n".
  2538.  
  2539. ==============================================================================
  2540. 5. Defining functions                    *user-functions*
  2541.  
  2542. New functions can be defined.  These can be called just like builtin
  2543. functions.
  2544.  
  2545. The function name must start with an uppercase letter, to avoid confusion with
  2546. builtin functions.  To prevent from using the same name in different scripts
  2547. avoid obvious, short names.  A good habit is to start the function name with
  2548. the name of the script, e.g., "HTMLcolor()".
  2549.  
  2550. It's also possible to use curly braces, see |curly-braces-names|.
  2551.  
  2552.                             *local-function*
  2553. A function local to a script must start with "s:".  A local script function
  2554. can only be called from within the script and from functions, user commands
  2555. and autocommands defined in the script.  It is also possible to call the
  2556. function from a mappings defined in the script, but then |<SID>| must be used
  2557. instead of "s:" when the mapping is expanded outside of the script.
  2558.  
  2559.                     *:fu* *:function* *E128* *E129* *E123*
  2560. :fu[nction]        List all functions and their arguments.
  2561.  
  2562. :fu[nction] {name}    List function {name}.
  2563.                             *E124* *E125*
  2564. :fu[nction][!] {name}([arguments]) [range] [abort]
  2565.             Define a new function by the name {name}.  The name
  2566.             must be made of alphanumeric characters and '_', and
  2567.             must start with a capital.
  2568.                         *function-argument* *a:var*
  2569.             An argument can be defined by giving its name.  In the
  2570.             function this can then be used as "a:name" ("a:" for
  2571.             argument).
  2572.             Up to 20 arguments can be given, separated by commas.
  2573.             Finally, an argument "..." can be specified, which
  2574.             means that more arguments may be following.  In the
  2575.             function they can be used as "a:1", "a:2", etc.  "a:0"
  2576.             is set to the number of extra arguments (which can be
  2577.             0).
  2578.             When not using "...", the number of arguments in a
  2579.             function call must be equal the number of named
  2580.             arguments.  When using "...", the number of arguments
  2581.             may be larger.
  2582.             It is also possible to define a function without any
  2583.             arguments.  You must still supply the () then.
  2584.             The body of the function follows in the next lines,
  2585.             until the matching |:endfunction|.  It is allowed to
  2586.             define another function inside a function body.
  2587.                                 *E127* *E122*
  2588.             When a function by this name already exists and [!] is
  2589.             not used an error message is given.  When [!] is used,
  2590.             an existing function is silently replaced.
  2591.             When the [range] argument is added, the function is
  2592.             expected to take care of a range itself.  The range is
  2593.             passed as "a:firstline" and "a:lastline".  If [range]
  2594.             is excluded, ":{range}call" will call the function for
  2595.             each line in the range, with the cursor on the start
  2596.             of each line.  See |function-range-example|.
  2597.             When the [abort] argument is added, the function will
  2598.             abort as soon as an error is detected.
  2599.             The last used search pattern and the redo command "."
  2600.             will not be changed by the function.
  2601.  
  2602.                     *:endf* *:endfunction* *E126* *E193*
  2603. :endf[unction]        The end of a function definition.
  2604.  
  2605.                     *:delf* *:delfunction* *E130* *E131*
  2606. :delf[unction] {name}    Delete function {name}.
  2607.  
  2608.                             *:retu* *:return* *E133*
  2609. :retu[rn] [expr]    Return from a function.  When "[expr]" is given, it is
  2610.             evaluated and returned as the result of the function.
  2611.             If "[expr]" is not given, the number 0 is returned.
  2612.             When a function ends without an explicit ":return",
  2613.             the number 0 is returned.
  2614.             Note that there is no check for unreachable lines,
  2615.             thus there is no warning if commands follow ":return".
  2616.  
  2617. Inside a function variables can be used.  These are local variables, which
  2618. will disappear when the function returns.  Global variables need to be
  2619. accessed with "g:".
  2620.  
  2621. Example: >
  2622.   :function Table(title, ...)
  2623.   :  echohl Title
  2624.   :  echo a:title
  2625.   :  echohl None
  2626.   :  let idx = 1
  2627.   :  while idx <= a:0
  2628.   :    exe "echo a:" . idx
  2629.   :    let idx = idx + 1
  2630.   :  endwhile
  2631.   :  return idx
  2632.   :endfunction
  2633.  
  2634. This function can then be called with: >
  2635.   let lines = Table("Table", "line1", "line2")
  2636.   let lines = Table("Empty Table")
  2637.  
  2638. To return more than one value, pass the name of a global variable: >
  2639.   :function Compute(n1, n2, divname)
  2640.   :  if a:n2 == 0
  2641.   :    return "fail"
  2642.   :  endif
  2643.   :  exe "let g:" . a:divname . " = ". a:n1 / a:n2
  2644.   :  return "ok"
  2645.   :endfunction
  2646.  
  2647. This function can then be called with: >
  2648.   :let success = Compute(13, 1324, "div")
  2649.   :if success == "ok"
  2650.   :  echo div
  2651.   :endif
  2652.  
  2653. An alternative is to return a command that can be executed.  This also works
  2654. with local variables in a calling function.  Example: >
  2655.   :function Foo()
  2656.   :  execute Bar()
  2657.   :  echo "line " . lnum . " column " . col
  2658.   :endfunction
  2659.  
  2660.   :function Bar()
  2661.   :  return "let lnum = " . line(".") . " | let col = " . col(".")
  2662.   :endfunction
  2663.  
  2664. The names "lnum" and "col" could also be passed as argument to Bar(), to allow
  2665. the caller to set the names.
  2666.  
  2667.                             *:cal* *:call* *E107*
  2668. :[range]cal[l] {name}([arguments])
  2669.         Call a function.  The name of the function and its arguments
  2670.         are as specified with |:function|.  Up to 20 arguments can be
  2671.         used.
  2672.         Without a range and for functions that accept a range, the
  2673.         function is called once.  When a range is given the cursor is
  2674.         positioned at the start of the first line before executing the
  2675.         function.
  2676.         When a range is given and the function doesn't handle it
  2677.         itself, the function is executed for each line in the range,
  2678.         with the cursor in the first column of that line.  The cursor
  2679.         is left at the last line (possibly moved by the last function
  2680.         call).  The arguments are re-evaluated for each line.  Thus
  2681.         this works:
  2682.                         *function-range-example*  >
  2683.     :function Mynumber(arg)
  2684.     :  echo line(".") . " " . a:arg
  2685.     :endfunction
  2686.     :1,5call Mynumber(getline("."))
  2687. <
  2688.         The "a:firstline" and "a:lastline" are defined anyway, they
  2689.         can be used to do something different at the start or end of
  2690.         the range.
  2691.  
  2692.         Example of a function that handles the range itself: >
  2693.  
  2694.     :function Cont() range
  2695.     :  execute (a:firstline + 1) . "," . a:lastline . 's/^/\t\\ '
  2696.     :endfunction
  2697.     :4,8call Cont()
  2698. <
  2699.         This function inserts the continuation character "\" in front
  2700.         of all the lines in the range, except the first one.
  2701.  
  2702.                                 *E132*
  2703. The recursiveness of user functions is restricted with the |'maxfuncdepth'|
  2704. option.
  2705.  
  2706.                             *autoload-functions*
  2707. When using many or large functions, it's possible to automatically define them
  2708. only when they are used.  Example: >
  2709.  
  2710.     :au FuncUndefined BufNet* source ~/vim/bufnetfuncs.vim
  2711.  
  2712. The file "~/vim/bufnetfuncs.vim" should then define functions that start with
  2713. "BufNet".  Also see |FuncUndefined|.
  2714.  
  2715. ==============================================================================
  2716. 6. Curly braces names                    *curly-braces-names*
  2717.  
  2718. Wherever you can use a variable, you can use a "curly braces name" variable.
  2719. This is a regular variable name with one or more expressions wrapped in braces
  2720. {} like this: >
  2721.     my_{adjective}_variable
  2722.  
  2723. When Vim encounters this, it evaluates the expression inside the braces, puts
  2724. that in place of the expression, and re-interprets the whole as a variable
  2725. name.  So in the above example, if the variable "adjective" was set to
  2726. "noisy", then the reference would be to "my_noisy_variable", whereas if
  2727. "adjective" was set to "quiet", then it would be to "my_quiet_variable".
  2728.  
  2729. One application for this is to create a set of variables governed by an option
  2730. value.  For example, the statement >
  2731.     echo my_{&background}_message
  2732.  
  2733. would output the contents of "my_dark_message" or "my_light_message" depending
  2734. on the current value of 'background'.
  2735.  
  2736. You can use multiple brace pairs: >
  2737.     echo my_{adverb}_{adjective}_message
  2738. ..or even nest them: >
  2739.     echo my_{ad{end_of_word}}_message
  2740. where "end_of_word" is either "verb" or "jective"
  2741.  
  2742. However, the expression inside the braces must evaluate to a valid single
  2743. variable name. e.g. this is invalid: >
  2744.     :let foo='a + b'
  2745.     :echo c{foo}d
  2746. .. since the result of expansion is "ca + bd", which is not a variable name.
  2747.  
  2748.                         *curly-braces-function-names*
  2749. You can call and define functions by an evaluated name in a similar way.
  2750. Example: >
  2751.     :let func_end='whizz'
  2752.     :call my_func_{func_end}(parameter)
  2753. <
  2754. This would call the function "my_func_whizz(parameter)"
  2755.  
  2756. ==============================================================================
  2757. 7. Commands                        *expression-commands*
  2758.  
  2759. :let {var-name} = {expr1}                *:let* *E18*
  2760.             Set internal variable {var-name} to the result of the
  2761.             expression {expr1}.  The variable will get the type
  2762.             from the {expr}.  if {var-name} didn't exist yet, it
  2763.             is created.
  2764.  
  2765. :let ${env-name} = {expr1}            *:let-environment* *:let-$*
  2766.             Set environment variable {env-name} to the result of
  2767.             the expression {expr1}.  The type is always String.
  2768.  
  2769. :let @{reg-name} = {expr1}            *:let-register* *:let-@*
  2770.             Write the result of the expression {expr1} in register
  2771.             {reg-name}.  {reg-name} must be a single letter, and
  2772.             must be the name of a writable register (see
  2773.             |registers|).  "@@" can be used for the unnamed
  2774.             register, "@/" for the search pattern.
  2775.             If the result of {expr1} ends in a <CR> or <NL>, the
  2776.             register will be linewise, otherwise it will be set to
  2777.             characterwise.
  2778.             This can be used to clear the last search pattern: >
  2779.                 :let @/ = ""
  2780. <            This is different from searching for an empty string,
  2781.             that would match everywhere.
  2782.  
  2783. :let &{option-name} = {expr1}            *:let-option* *:let-star*
  2784.             Set option {option-name} to the result of the
  2785.             expression {expr1}.  The value is always converted to
  2786.             the type of the option.
  2787.             For an option local to a window or buffer the effect
  2788.             is just like using the |:set| command: both the local
  2789.             value and the global value is changed.
  2790.  
  2791. :let &l:{option-name} = {expr1}
  2792.             Like above, but only set the local value of an option
  2793.             (if there is one).  Works like |:setlocal|.
  2794.  
  2795. :let &g:{option-name} = {expr1}
  2796.             Like above, but only set the global value of an option
  2797.             (if there is one).  Works like |:setglobal|.
  2798.  
  2799.                             *E106*
  2800. :let {var-name}    ..    List the value of variable {var-name}.  Several
  2801.             variable names may be given.
  2802.  
  2803. :let            Liset the values of all variables.
  2804.  
  2805.                             *:unlet* *:unl* *E108*
  2806. :unl[et][!] {var-name} ...
  2807.             Remove the internal variable {var-name}.  Several
  2808.             variable names can be given, they are all removed.
  2809.             With [!] no error message is given for non-existing
  2810.             variables.
  2811.  
  2812. :if {expr1}                    *:if* *:endif* *:en* *E171*
  2813. :en[dif]        Execute the commands until the next matching ":else"
  2814.             or ":endif" if {expr1} evaluates to non-zero.
  2815.  
  2816.             From Vim version 4.5 until 5.0, every Ex command in
  2817.             between the ":if" and ":endif" is ignored.  These two
  2818.             commands were just to allow for future expansions in a
  2819.             backwards compatible way.  Nesting was allowed.  Note
  2820.             that any ":else" or ":elseif" was ignored, the "else"
  2821.             part was not executed either.
  2822.  
  2823.             You can use this to remain compatible with older
  2824.             versions: >
  2825.                 :if version >= 500
  2826.                 :  version-5-specific-commands
  2827.                 :endif
  2828. <
  2829.                             *:else* *:el*
  2830. :el[se]            Execute the commands until the next matching ":else"
  2831.             or ":endif" if they previously were not being
  2832.             executed.
  2833.  
  2834.                             *:elseif* *:elsei*
  2835. :elsei[f] {expr1}    Short for ":else" ":if", with the addition that there
  2836.             is no extra ":endif".
  2837.  
  2838. :wh[ile] {expr1}        *:while* *:endwhile* *:wh* *:endw* *E170*
  2839. :endw[hile]        Repeat the commands between ":while" and ":endwhile",
  2840.             as long as {expr1} evaluates to non-zero.
  2841.             When an error is detected from a command inside the
  2842.             loop, execution continues after the "endwhile".
  2843.  
  2844.             NOTE: The ":append" and ":insert" commands don't work
  2845.             properly inside a ":while" loop.
  2846.  
  2847.                             *:continue* *:con*
  2848. :con[tinue]        When used inside a ":while", jumps back to the
  2849.             ":while".
  2850.  
  2851.                             *:break* *:brea*
  2852. :brea[k]        When used inside a ":while", skips to the command
  2853.             after the matching ":endwhile".
  2854.  
  2855.                             *:ec* *:echo*
  2856. :ec[ho] {expr1} ..    Echoes each {expr1}, with a space in between and a
  2857.             terminating <EOL>.  Also see |:comment|.
  2858.             Use "\n" to start a new line.  Use "\r" to move the
  2859.             cursor to the first column.
  2860.             Cannot be followed by a comment.
  2861.             Example: >
  2862.         :echo "the value of 'shell' is" &shell
  2863. <            A later redraw may make the message disappear again.
  2864.             To avoid that a command from before the ":echo" causes
  2865.             a redraw afterwards (redraws are often postponed until
  2866.             you type something), force a redraw with the |:redraw|
  2867.             command.  Example: >
  2868.         :new | redraw | echo "there is a new window"
  2869. <
  2870.                             *:echon*
  2871. :echon {expr1} ..    Echoes each {expr1}, without anything added.  Also see
  2872.             |:comment|.
  2873.             Cannot be followed by a comment.
  2874.             Example: >
  2875.                 :echon "the value of 'shell' is " &shell
  2876. <
  2877.             Note the difference between using ":echo", which is a
  2878.             Vim command, and ":!echo", which is an external shell
  2879.             command: >
  2880.         :!echo %        --> filename
  2881. <            The arguments of ":!" are expanded, see |:_%|. >
  2882.         :!echo "%"        --> filename or "filename"
  2883. <            Like the previous example.  Whether you see the double
  2884.             quotes or not depends on your 'shell'. >
  2885.         :echo %            --> nothing
  2886. <            The '%' is an illegal character in an expression. >
  2887.         :echo "%"        --> %
  2888. <            This just echoes the '%' character. >
  2889.         :echo expand("%")    --> filename
  2890. <            This calls the expand() function to expand the '%'.
  2891.  
  2892.                             *:echoh* *:echohl*
  2893. :echoh[l] {name}    Use the highlight group {name} for the following
  2894.             ":echo[n]" commands.  Example: >
  2895.         :echohl WarningMsg | echo "Don't panic!" | echohl None
  2896. <            Don't forget to set the group back to "None",
  2897.             otherwise all following echo's will be highlighted.
  2898.  
  2899.                             *:echom* *:echomsg*
  2900. :echom[sg] {expr1} ..    Echo the expression(s) as a true message, saving the
  2901.             message in the |message-history|.
  2902.             Spaces are placed between the arguments as with the
  2903.             :echo command.
  2904.             Example: >
  2905.         :echomsg "It's a Zizzer Zazzer Zuzz, as you can plainly see."
  2906. <
  2907.                             *:echoe* *:echoerr*
  2908. :echoe[rr] {expr1} ..    Echo the expression(s) as an error message, saving the
  2909.             message in the |message-history|.
  2910.             Spaces are placed between the arguments as with the
  2911.             :echo command.
  2912.             Example: >
  2913.         :echoerr "This script just failed!"
  2914. <
  2915.                             *:exe* *:execute*
  2916. :exe[cute] {expr1} ..    Executes the string that results from the evaluation
  2917.             of {expr1} as an Ex command.  Multiple arguments are
  2918.             concatenated, with a space in between.
  2919.             Cannot be followed by a comment.
  2920.             Examples: >
  2921.         :execute "buffer " nextbuf
  2922.         :execute "normal " count . "w"
  2923. <
  2924.             Execute can be used to append a next command to
  2925.             commands that don't accept a '|'.  Example: >
  2926.         :execute '!ls' | echo "theend"
  2927.  
  2928. <            Execute is also a nice way to avoid having to type
  2929.             control characters in a Vim script for a ":normal"
  2930.             command: >
  2931.         :execute "normal ixxx\<Esc>"
  2932. <            This has an <Esc> character, see |expr-string|.
  2933.  
  2934.             Note: The executed string may be any command-line, but
  2935.             you cannot start or end a "while" or "if" command.
  2936.             Thus this is illegal: >
  2937.         :execute 'while i > 5'
  2938.         :execute 'echo "test" | break'
  2939. <
  2940.             It is allowed to have a "while" or "if" command
  2941.             completely in the executed string: >
  2942.         :execute 'while i < 5 | echo i | let i = i + 1 | endwhile'
  2943. <
  2944.  
  2945.                             *:comment*
  2946.             ":execute", ":echo" and ":echon" cannot be followed by
  2947.             a comment directly, because they see the '"' as the
  2948.             start of a string.  But, you can use '|' followed by a
  2949.             comment.  Example: >
  2950.         :echo "foo" | "this is a comment
  2951.  
  2952. ==============================================================================
  2953. 8. Examples                        *eval-examples*
  2954.  
  2955. Printing in Hex ~
  2956. >
  2957.   :" The function Nr2Hex() returns the Hex string of a number.
  2958.   :func Nr2Hex(nr)
  2959.   :  let n = a:nr
  2960.   :  let r = ""
  2961.   :  while n
  2962.   :    let r = '0123456789ABCDEF'[n % 16] . r
  2963.   :    let n = n / 16
  2964.   :  endwhile
  2965.   :  return r
  2966.   :endfunc
  2967.  
  2968.   :" The function String2Hex() converts each character in a string to a two
  2969.   :" character Hex string.
  2970.   :func String2Hex(str)
  2971.   :  let out = ''
  2972.   :  let ix = 0
  2973.   :  while ix < strlen(a:str)
  2974.   :    let out = out . Nr2Hex(char2nr(a:str[ix]))
  2975.   :    let ix = ix + 1
  2976.   :  endwhile
  2977.   :  return out
  2978.   :endfunc
  2979.  
  2980. Example of its use: >
  2981.   :echo Nr2Hex(32)
  2982. result: "20" >
  2983.   :echo String2Hex("32")
  2984. result: "3332"
  2985.  
  2986.  
  2987. Sorting lines (by Robert Webb) ~
  2988.  
  2989. Here is a vim script to sort lines.  Highlight the lines in vim and type
  2990. ":Sort".  This doesn't call any external programs so it'll work on any
  2991. platform.  The function Sort() actually takes the name of a comparison
  2992. function as its argument, like qsort() does in C.  So you could supply it
  2993. with different comparison functions in order to sort according to date etc.
  2994. >
  2995.   :" Function for use with Sort(), to compare two strings.
  2996.   :func! Strcmp(str1, str2)
  2997.   :  if (a:str1 < a:str2)
  2998.   :    return -1
  2999.   :  elseif (a:str1 > a:str2)
  3000.   :    return 1
  3001.   :  else
  3002.   :    return 0
  3003.   :  endif
  3004.   :endfunction
  3005.  
  3006.   :" Sort lines.  SortR() is called recursively.
  3007.   :func! SortR(start, end, cmp)
  3008.   :  if (a:start >= a:end)
  3009.   :    return
  3010.   :  endif
  3011.   :  let partition = a:start - 1
  3012.   :  let middle = partition
  3013.   :  let partStr = getline((a:start + a:end) / 2)
  3014.   :  let i = a:start
  3015.   :  while (i <= a:end)
  3016.   :    let str = getline(i)
  3017.   :    exec "let result = " . a:cmp . "(str, partStr)"
  3018.   :    if (result <= 0)
  3019.   :        " Need to put it before the partition.  Swap lines i and partition.
  3020.   :        let partition = partition + 1
  3021.   :        if (result == 0)
  3022.   :        let middle = partition
  3023.   :        endif
  3024.   :        if (i != partition)
  3025.   :        let str2 = getline(partition)
  3026.   :        call setline(i, str2)
  3027.   :        call setline(partition, str)
  3028.   :        endif
  3029.   :    endif
  3030.   :    let i = i + 1
  3031.   :  endwhile
  3032.  
  3033.   :  " Now we have a pointer to the "middle" element, as far as partitioning
  3034.   :  " goes, which could be anywhere before the partition.  Make sure it is at
  3035.   :  " the end of the partition.
  3036.   :  if (middle != partition)
  3037.   :    let str = getline(middle)
  3038.   :    let str2 = getline(partition)
  3039.   :    call setline(middle, str2)
  3040.   :    call setline(partition, str)
  3041.   :  endif
  3042.   :  call SortR(a:start, partition - 1, a:cmp)
  3043.   :  call SortR(partition + 1, a:end, a:cmp)
  3044.   :endfunc
  3045.  
  3046.   :" To Sort a range of lines, pass the range to Sort() along with the name of a
  3047.   :" function that will compare two lines.
  3048.   :func! Sort(cmp) range
  3049.   :  call SortR(a:firstline, a:lastline, a:cmp)
  3050.   :endfunc
  3051.  
  3052.   :" :Sort takes a range of lines and sorts them.
  3053.   :command! -nargs=0 -range Sort <line1>,<line2>call Sort("Strcmp")
  3054. <
  3055.                             *sscanf*
  3056. There is no sscanf() function in Vim.  If you need to extract parts from a
  3057. line, you can use matchstr() and substitute() to do it  This example shows
  3058. how to get the file name, line number and column number out of a line like
  3059. "foobar.txt, 123, 45". >
  3060.    :" Set up the match bit
  3061.    :let mx='\(\f\+\),\s*\(\d\+\),\s*\(\d\+\)'
  3062.    :"get the part matching the whole expression
  3063.    :let l = matchstr(line, mx)
  3064.    :"get each item out of the match
  3065.    :let file = substitute(l, mx, '\1', '')
  3066.    :let lnum = substitute(l, mx, '\2', '')
  3067.    :let col = substitute(l, mx, '\3', '')
  3068.  
  3069. The input is in the variable "line", the results in the variables "file",
  3070. "lnum" and "col". (idea from Michael Geddes)
  3071.  
  3072. ==============================================================================
  3073. 9. No +eval feature                *no-eval-feature*
  3074.  
  3075. When the |+eval| feature was disabled at compile time, none of the expression
  3076. evaluation commands are available.  To prevent this from causing Vim scripts
  3077. to generate all kinds of errors, the ":if" and ":endif" commands are still
  3078. recognized, though the argument of the ":if" and everything between the ":if"
  3079. and the matching ":endif" is ignored.  Nesting of ":if" blocks is allowed, but
  3080. only if the commands are at the start of the line.  The ":else" command is not
  3081. recognized.
  3082.  
  3083. Example of how to avoid executing commands when the |+eval| feature is
  3084. missing: >
  3085.  
  3086.     :if 1
  3087.     :  echo "Expression evaluation is compiled in"
  3088.     :else
  3089.     :  echo "You will _never_ see this message"
  3090.     :endif
  3091. <
  3092. ==============================================================================
  3093. 10. The sandbox                    *eval-sandbox* *sandbox* *E48*
  3094.  
  3095. The 'foldexpr', 'includeexpr', 'indentexpr', 'statusline' and 'foldtext'
  3096. options are evaluated in a sandbox.  This means that you are protected from
  3097. these expression having nasty side effects.  This gives some safety for when
  3098. these options are set from a modeline.  It is also used when the command from
  3099. a tags file is executed.
  3100. This is not guaranteed 100% secure, but it should block most attacks.
  3101.  
  3102. These items are not allowed in the sandbox:
  3103.     - changing the buffer text
  3104.     - defining or changing mapping, autocommands, functions, user commands
  3105.     - setting an option with ":set"
  3106.     - executing a shell command
  3107.     - reading or writing a file
  3108.     - jumping to another buffer or editing a file
  3109.  
  3110.  vim:tw=78:ts=8:ft=help:norl:
  3111.